Monday, April 20, 2015

Linked List

//============================================================================
// Name        : Employee.cpp
// Author      : Zachary Standridge
// Version     :over a billion
// Copyright   : You wouldn't download a car would you?
// Description : Create and organize a list
//============================================================================

#include <iostream>

using namespace std;

struct  node
{
    int number;
    node *next;
};

bool isEmpty(node *head);
char menu();
void insertAsFirstElement(node *&head, node *&last, int number);
void insert(node *&head, node *&last, int number);
void remove(node *&head, node *&last);
void showList(node *current);

bool isEmpty(node *head)
{
    if(head == NULL)
        return true;
    else
        return false;
}
char menu()
{
    char choice;

    cout <<"Menu\n";
    cout <<"------------------\n";
    cout <<"1. Add Number\n";
    cout <<"2. Remove Number\n";
    cout <<"3. Show List\n";
    cout <<"4. Exit\n";

    cin >> choice;
    return choice;
}
void insertAsFirstElement(node *&head, node *&last, int number)
{
    node *temp = new node;
    temp ->number = number;
    temp ->next = NULL;
    head = temp;
    last = temp;
}
void insert(node *&head, node *&last, int number)
{
    if(isEmpty(head))
        insertAsFirstElement(head,last,number);
    else
        {
        node *temp = new node;
        temp ->number = number;
        temp ->next = NULL;
        last ->next = temp;
        last = temp;
        }
}
void remove(node *&head, node *&last)
{
    if (isEmpty(head))
        cout<<"There is nothing here\n";
    else if (head == last)
        {
        delete head;
        head == NULL;
        last == NULL;
        }
    else
    {
        node *temp = head;
        head = head->next;
        delete temp;
    }

}
void showList(node *current)
{
   if(isEmpty(current))
       cout<< "The list is empty.\n";
   else
   {
    cout << "The list contains : \n";
    while (current != NULL)
       {
           cout << current -> number << endl;
           current = current->next;
       }
   }
}

int main ()
{
    node *head = NULL;
    node *last = NULL;
    char choice;
    int number;
    do
        {
        choice = menu ();
        switch(choice)
               {
                case '1': cout<< "Please enter a number;";
                cin>>number;
                insert(head, last,number);
                break;
                case '2': remove (head, last);
                break;
                case '3': showList(head);
                break;
                default: cout<< "System exit\n";
               }
        }
        while(choice != '4');
    return 0;
}

Thursday, April 2, 2015

Employee (Amended) This time it checks for shift number, pay rate, and employee number


#include <iostream>
#include <string>
using namespace std;

class Employee
{
private:
    string employeeName;
    int employeeNumber;
    string hireDate;
    //member function to validate the E number
    void checkEmployeeNumber()
    {
        if (employeeNumber < 0 ||employeeNumber > 9999 )
            throw invalidEmployeeNumber();
    }
public:
    //exception class
    class invalidEmployeeNumber
    {};
    //constructors
    Employee (string name, int number, string hDate)
    {
        //set variables
        employeeName = name;
        employeeNumber = number;
        hireDate = hDate;

        //check the employee number
        checkEmployeeNumber();
    }
    //mutators
    void setEmployeeName (string name)
    {
        employeeName=name;
    }
    void setEmployeeNumber (int number)
    {
        employeeNumber=number;
        checkEmployeeNumber();
    }
    void setHireDate (string hDate)
    {
        hireDate = hDate;
    }
    //accessors
    string getEmployeeName() const
    {
        return employeeName;
    }
    int getEmployeeNumber() const
    {
        return employeeNumber;
    }
    string getHireDate () const
    {
        return hireDate;
    }

};
class ProductionWorker:
    public Employee
    {
    private:
        int shift;
        double hourlyPayRate;
        //member function checking shift number
        void checkShift()
        {
            if
                (shift < 1 || shift > 2)
                    throw InvalidShift();
        }
        // checking pay rate
        void checkPayRate()
        {
            if
                (hourlyPayRate < 0)
                    throw InvalidPayRate();
        }

    public:
        //exception class
        class InvalidShift
        {};
        class InvalidPayRate
        {};
        //constructors
        ProductionWorker (string name, int number, string hDate, int shiftNum, double payRate):
                Employee (name, number, hDate)
                {
                    //set the member variables
                    shift = shiftNum;
                    hourlyPayRate = payRate;
                    //check the shift and pay rate
                    checkShift();
                    checkPayRate();
                }
        //mutators
        void setShift (int shiftNum)
        {
        shift = shiftNum;
        checkShift();
        }
        void setHourlyPayRate (double payRate)
        {
        hourlyPayRate = payRate;
        checkPayRate();
        }
        //accessors
        int getShift () const
        {
            return shift;
        }
        double getHourPayRate()
        {
            return hourlyPayRate;
        }
    };
    //prototype
    void testValues (string, int, string, int, double);

    int main()
    {
//test good data
       cout <<" Testing good data....\n";
       testValues("Pedro Colon", 1234, "12/01/2000",1,550.00);
//test bad shift number
       cout <<"\n Testing bad shift number....\n";
       testValues("Pedro Colon", 1234, "12/01/2000",9,550.00);
//test bad employee number
       cout <<"\n Testing bad employee number....\n";
       testValues("Pedro Colon", 91234, "12/01/2000",1,550.00);
//test bad pay rate
       cout <<"\n Testing  bad pay rate ....\n";
       testValues("Pedro Colon", 1234, "12/01/2000",1,-550.00);
       return 0;
    }
void testValues (string name, int number, string hDate, int shift, double payRate)
{
    try
            {
            ProductionWorker (name, number, hDate, shift, payRate);
            //good stuff
            cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
            cout<<"\n Good data\n" ;
            }
        catch (ProductionWorker::invalidEmployeeNumber)
            {
            cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
            cout<<"\nInvalid Employee Number encountered \n";
            }
        catch (ProductionWorker::InvalidShift)
            {
            cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
            cout<<"\nInvalid Shift Number encountered \n";
            }
        catch (ProductionWorker::InvalidPayRate)
            {
            cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
            cout<<"\nInvalid Pay Rate encountered \n";
            }
}

Tuesday, March 17, 2015

Employee and productionWorker c++



#include <string>
#include <iostream>
using namespace std;

//-----------------------------------------------------------------//
//-------------------------class employee--------------------------//
//-----------------------------------------------------------------//
class Employee
{
private: string empName;
int empNum;
string hireDate;
public:
Employee():empName(""),empNum(0), hireDate("") //default ctor
{}

Employee(string name, int num, string date)
{
empName = name;
empNum = num;
hireDate = date;
}

void setempName(string n);
void setempNum(int nm);
void setHiredate(string d);
string getName();
int getNum();
string getDate();
void print();
};

void Employee::setempName(string n)
{empName = n ;}

void Employee::setempNum(int nm)
{empNum = nm;}

void Employee::setHiredate(string d)
{hireDate = d;}

string Employee::getName()
{return empName;}

int Employee::getNum()
{return empNum;}

string Employee::getDate()
{return hireDate;}
//-----------------------------------------------------------------//
//--------------------class production worker----------------------//
//-----------------------------------------------------------------//
class ProductionWorker : public Employee
{
private:
int shift;
double hrlyPay;
public:
ProductionWorker():shift(0) , hrlyPay(0.0)
{}

ProductionWorker(int sh , double pay)
{
shift = sh;
hrlyPay = pay;
}

void setshift(int s);
void setPay(double p);
int getshift();
double getPay();
void print();
};

void ProductionWorker::print()
{
cout << "Employee Name: " << getName() << endl;
cout << "Employee Number: " << getNum() << endl;
    cout << "Hire Date: " << getDate() << endl;
    cout << "Shift: " << getshift();

if(shift == 1)
{
cout << "(Day Shift)" << endl;}
else
cout << "(Night Shift)" << endl;

    cout << "Pay Rate: $" << getPay()<< endl;
}

void ProductionWorker::setshift(int sh)
{sh = shift;}

void ProductionWorker::setPay(double p)
{p = hrlyPay;}

int ProductionWorker::getshift()
{return shift;}

double ProductionWorker::getPay()
{return hrlyPay;}
//-----------------------------------------------------------------//
//-------------------------Main------------------------------------//
//-----------------------------------------------------------------//
int main()
{
int Shift;
double pay;
cout << "Enter 1 for Day Shift or 2 for Night Shift: "<<endl;
cout<< "Any deviation will default to Night Shift ";
cin >> Shift;
cout << "Enter hourly pay: $";
cin >> pay;
    ProductionWorker emp1(Shift, pay);
emp1.setempName("Pedro, Colon");
emp1.setempNum(8675309);
emp1.setHiredate("1-1-2000");
emp1.print();
return 0;
}

Saturday, February 21, 2015

c++ date conversion

//============================================================================
// Name        : Assignment.cpp
// Author      : Zachary Standridge
// Version     :over a billion
// Copyright   : You wouldn't download a car would you?
// Description : convert simple entered dates into week number and Semester with year at the end.
//============================================================================

#include <iostream>
#include <cmath>
#include <string>
#include <stdio.h>

using namespace std;
class week

{
int month;
int day;
int year;
public:
week (int month = 1, int day = 1, int year = 1,int weekNum = 0,int semesterNum = 1,
double week = 0, double ineedthisnum = 0, double thisonetoo =0 )
{
week::month = month;
week::day = day;
week::year = year;
};
void showWeek();
~week(){}
};
int main()
{
int month;
int day;
int year;
//--------------------------------month----------------------------------
cout<<"Enter Date"<<endl;
cout << "Enter month (between 1 and 12)" << endl;
cin >> month;
if
(month > 12 || month < 1)
{
month = 1;
}
//--------------------------------day----------------------------------
cout << "Enter day (between 1 and 31)" << endl;
cin >> day;
if
(day > 31 || day < 1)
{
day = 1;
}
//--------------------------------year----------------------------------
cout << "Enter year (between 1900 and 2030)"<< endl;
cin >> year;
if
(year > 2030 || year < 1900)
{
year = 1900;
}
week newDate(month, day, year);
//==================================Week=================================
double week = 0.00000;
double ineedthisnum = 0.00000;
{
week = day ;
//cout<<" Week #----------> " << week<<endl;
ineedthisnum = month;
ineedthisnum = ineedthisnum *  29.6041667; //converts months to days
ineedthisnum = ineedthisnum - 29.604; //sets January to adding 0 days
week = ineedthisnum + week;       //adds days to months(days)
// cout<<" Week #----------> " << week<<endl;
week = week / 365;                //days divided by days in the year
//cout<<" Week #----------> " << week<<endl;
week = week * 52;                  //Converts to weeks in a year
//cout<<" Week #----------> " << week<<endl;
week = ceil(week);                 //rounds up
}
//cout<<" Week #----------> " << week<<endl;
//==================================Semester=============================
double thisonetoo = 0;
int semesterNum;
//cout<<""<< "month"<<month<<endl;
thisonetoo = month;
//converts months to temp value
//cout<<""<< thisonetoo<<endl;
thisonetoo = thisonetoo / 12; //percentage of the year past
//cout<<""<< thisonetoo<<endl;
thisonetoo = thisonetoo * 3; //numbers of semesters
//cout<<""<< thisonetoo<<endl;
thisonetoo = round(thisonetoo);
if ( thisonetoo <=0 )                  //back up for low numbers
{
thisonetoo = thisonetoo + 1;
}
else
{
thisonetoo = thisonetoo*1;
}
semesterNum =  static_cast<int>(thisonetoo);
//cout<<" semester #----------> " << semesterNum<<endl;
//be sure to commented out all the couts while watching the data being changed.
//=======================================================================
//cout<<"\n\n"<<month<<"/"<<day<<"/"<<year<<"\n is"<<endl;
// required output ------------------Week 5, Spring 2015
//cout<<"Week "<< week<<endl;
//cout<<"Semester "<< semesterNum<<endl;

if (semesterNum == 1)
cout<<"Week "<< week<<", Spring " << year<< endl;
else if (semesterNum == 2)
cout<<"Week "<< week<<", Summer " << year<< endl;
else if (semesterNum == 3)
cout<<"Week "<< week<<", Fall " << year<< endl;
else
cout<<"Something has gone seriously wrong!"<< endl;
return 0;
}

Saturday, January 31, 2015

MovieData

The program should create two MovieData variables, store values in
their members, and pass each one, in turn, to a function that displays the
information about the movie in a clearly formatted manner


#include <iostream>
#include <string>

using namespace std;

struct MovieData
{
 string m, n, o, p;
 MovieData (string, string, string, string);
};
//Make a constructor
MovieData::MovieData (string a, string b, string c, string d) {
    m = a;
    n = b;
    o = c;
    p = d;
}

void printinfo (MovieData Q)
{
cout<<"Title:         "<<Q.m<<endl;
cout<<"Director:      "<<Q.n<<endl;
cout<<"Year Released: "<<Q.o<<endl;
cout<<"Writer:  "<<Q.p<<endl;
}

int main()
{
    string title;
string direct;
string yearR;
string writer;
//title
    std::cout << "Enter title of movie:\n";
    std::getline(std::cin, title);
//director
    std::cout << "Enter the Director of movie:\n";
    std::getline(std::cin, direct);
//year
    std::cout << "Enter the year movie was released:\n";
    std::getline(std::cin, yearR);
//writer
    std::cout << "Enter writer of the screenplay:\n";
    std::getline(std::cin, writer);

MovieData movie1(title, direct, yearR, writer);
    //=====================================================//
//title
    std::cout << "Enter title of movie:\n";
    std::getline(std::cin, title);
//director
    std::cout << "Enter the Director of movie:\n";
    std::getline(std::cin, direct);
//year
    std::cout << "Enter the year movie was released:\n";
    std::getline(std::cin, yearR);
//writer
    std::cout << "Enter writer of the screenplay:\n";
    std::getline(std::cin, writer);
MovieData movie2(title, direct, yearR, writer);
//i know this could be done in a loop...//
//===========================================================//

//Call function to Display the results.
    cout<<"\n\nHere is the Movie Data:\n";
    cout<<"Movie 1:";
    cout<<"\n-----------------------\n";

printinfo (movie1);
    cout<<"\n\nMovie 2:";
    cout<<"\n-----------------------\n";

printinfo (movie2);

return 0;
}

Friday, December 12, 2014

Math C++

  Write a C++ program that creates the following functions:

 double Max (double Values[], int size);

 double Min (double Values[], int size);

 double calc Average(double Values[], int size);

 double calc Median(double Values[], int size);

double calc Standard Deviation (double Values[], int size);

 Write a driver program that creates an array with 11 values and calculates all of the preceding values. Display the values to the user. Create a second array that has 10 values and display all of the preceding values.

Note: You do not need to get input from the user. Must use the previous functions prototype.





#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

double calcMax (int arg[], int length)
{
    int maxValue = 0;
    for(int i = 0; i < length; i++)
        {
        if(arg[i] > maxValue)
        {
            maxValue = arg[i];
        }

        }
         cout << "The highest value is: " << maxValue<<endl;

}
double calcMin (int arg[], int length)
{
    int minValue = 1000;
    for(int i = 0; i < length; i++)
        {
        if(arg[i] < minValue)
        {
            minValue = arg[i];
        }

        }
        cout << "The minimum value is: " << minValue<<endl;

}
double calcAverage (int arg[], int length)
{
int sum=0;
for (int i=0; i<length; i++)
sum += arg[i];

cout << "The average value is: " << sum/length<<endl;


}
double calcMedian (int arg[], int length)
{
    sort(arg, arg + length);
    cout << "The new sorted array looks like this." << endl;
    cout << "=====================================" << endl;
    for (size_t i = 0; i != length; ++i)
        cout << arg[i] << " ";
{    double* dpSorted = new double[length];
    for (int i = 0; i < length; ++i) {
        dpSorted[i] = arg[i];
    }
    for (int i = length - 1; i > 0; --i) {
        for (int j = 0; j < i; ++j) {
            if (dpSorted[j] > dpSorted[j+1]) {
                double dTemp = dpSorted[j];
                dpSorted[j] = dpSorted[j+1];
                dpSorted[j+1] = dTemp;
            }
        }
    }

        double dMedian = 0.0;
    if ((length % 2) == 0) {
        dMedian = (dpSorted[length/2] + dpSorted[(length/2) - 1])/2.0;
    } else {
        dMedian = dpSorted[length/2];
    }
    delete [] dpSorted;
     cout << "                              " << endl;
     cout << "The median value is: " << dMedian<<endl;
 }
 }
double calcStandardDev (int arg[], int length)
{
double deviation;
double sum2;
double mean;
for ( int i = 0; i <=length; i++ )
{
sum2 += pow((arg[i]-mean),2);
}
deviation= sqrt(sum2/(length-1));
cout << "The Standard Deviation is : " <<deviation<<endl;
cout << "                              " << endl;
cout << "                              " << endl;
cout << "                              " << endl;
cout << "                              " << endl;

}

int main ()
{

    int number1 [] = {1,2,3,4,25,6,7,8,9,11,12};
    calcMax(number1, 11);
    calcMin(number1, 11);
    calcAverage(number1,11);
    calcMedian(number1, 11);
    calcStandardDev(number1,11);
    int number2 [] ={10,9,8,7,6,5,4,3,2,1,11};
    calcMax(number2, 10);
    calcMin(number2, 10);
    calcAverage(number2,10);
    calcMedian(number2, 10);
    calcStandardDev(number2,10);

  return 0;
}

Tuesday, December 2, 2014

C++ Pay problem


/////////////////////////////////////////////////////////////////////////////////////////////////////
// Program Description:Write a program that calculates the daily      //
////pay and total pay of a person who works for a penny the first       //
//day and their pay doubles every day after that. The program must //
// calculate the salary and not just output the pay. Use the                 //
//  following variables:                                                                        //
//                                                                                                          //
// Input:     days worked                                                                      //
// Processing: pay cubed + running total                                            //
// Output:     pay grid of money earned                                              //
///////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include <iostream>
#include <cmath>
using namespace std;
    int main ()
    {
        int days, maxValue = 0;
        float wages = 0;
        float totalpay = 0;
        float runningtotal = 0;

        cout <<"Please enter the number of days worked: ";

        cin >> maxValue;
        cout << "Day \t\tPay \t\tTotal Pay" <<endl;
        cout <<"----------------------------------------" <<endl;
         for (days = 1; days <= maxValue; days++)
        {
            if (days==1)
                {
                    wages = .01;
                    runningtotal = wages;
                    totalpay = .01;
                }
            else if (days==2)
                {
                    wages = wages + .01;
                    runningtotal = wages;
                    totalpay = .03;
                }
            else
                {
                    wages = ((wages) * (2));
                    runningtotal = wages;
                    totalpay = wages + runningtotal -.01;
                }
        cout <<days<<"\t\t"<<wages<<"\t\t"<< totalpay<< endl;
        }
        return 0;
    }

Friday, November 21, 2014

C++ Pointer Lab

Exercise 1: Declare 2 int variables x and y and 2 int* pointer variables p and q.  Set x to 2, y to 8, p to the address of x, and q to the address of y.  Then print the following information:
Exercise 2: Declare 3 int variables x, y, z and 3 int* pointer variables p, q, r.  Set x, y, z to three distinct values.  Set p, q, r to the addresses of x, y, z respectively.





/*
// Author:Zachary //
//                                                                               //
// Date:                    11/10/14 23:34                        //
//                                                                             //
// Input:  None                                                       //
 */

#include<iostream>
#include <algorithm>    // std::swap

using namespace std;
void Exone ()
//Exercise 1: Declare 2 int variables x and y and 2 int* pointer variables p and q.//
//Set x to 2, y to 8, p to the address //
//of x, and q to the address of y.  Then print the following information://
{
    int x,y;
int *p,*q;
    x=2;
y=8;
p=&x;
q=&y;
cout<<"--------------------Exercise 1:------------------"<<endl;
cout<<"-------------------------------------------------"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"The address of x is "<<&x<<" and the value of x is "<<x<<endl;//(1) The address of x and the value of x.
cout<<"The value of p is "<<p<<" and the value of *p is "<<*p<<endl;//(2) The value of p and the value of *p.
cout<<"The address of y is "<<&y<<" and the value of y is "<<y<<endl;//(3) The address of y and the value of y.
cout<<"The value of q is "<<q<<" and the value of *q "<<*q<<endl;//(4) The value of q and the value of *q.
cout<<"The address of p (not its contents!) is "<<&p<<endl;//(5) The address of p (not its contents!).
cout<<"The address of q (not its contents!) is "<<&q<<endl;//(6) The address of q (not its contents!).
}
void Extwo()
//Exercise 2: Declare 3 int variables x, y, z and 3 int* pointer variables p, q, r.  //
//Set x, y, z to three distinct values.  Set p, q, r to the addresses of x, y, z respectively.//
{
    {
        int x,y,z;
        int *p,*q,*r;
        x=1;
        y=2;
        z=3;
        p=&x;
        q=&y;
        r=&z;
        cout<<" "<<endl;

        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<"--------------------Exercise 2:------------------"<<endl;
        cout<<"-------------------------------------------------"<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        //(1) Print with labels the values of x, y, z, p, q, r, *p, *q, *r.
        cout<<"value of x is "<<x<<endl;
        cout<<"value of y is "<<y<<endl;
        cout<<"value of z is "<<z<<endl;
        cout<<"value of p is "<<p<<endl;
        cout<<"value of q is "<<q<<endl;
        cout<<"value of r is "<<r<<endl;
        cout<<"value of *p is "<<*p<<endl;
        cout<<"value of *q is "<<*q<<endl;
        cout<<"value of *r is "<<*r<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        //(2) Print the message: Swapping values.
        cout<<"!!!!!!!SWAPPING VALUES!!!!!!"<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        //(3) Execute the swap code: z = x; x = y; y = z;
      std::swap(z,x);
      std::swap(x,y);
      std::swap(y,z);
      //(4) Print with labels the values of x, y, z, p, q, r, *p, *q, *r.
        cout<<"value of x is "<<x<<endl;
        cout<<"value of y is "<<y<<endl;
        cout<<"value of z is "<<z<<endl;
        cout<<"value of p is "<<p<<endl;
        cout<<"value of q is "<<q<<endl;
        cout<<"value of r is "<<r<<endl;
        cout<<"value of *p is "<<*p<<endl;
        cout<<"value of *q is "<<*q<<endl;
        cout<<"value of *r is "<<*r<<endl;
    }
}
int main()
{
Exone();
Extwo();
  return 0;
}//end main

Four by Four Array

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
const int ROW = 4;
const int COL = 4;
unsigned seed = time(0);
srand(seed);
int FourbyFour[ROW][COL] = {{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10},
{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10},
{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10},
{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10}};
int sum;
cout << endl;

for (int x = 0; x < ROW; x++)
{
for (int y = 0; y < COL; y++)
{
cout << "  " << setw(2) << FourbyFour[x][y] << "  ";
}

cout << endl;
}

sum = (FourbyFour[0][0] + FourbyFour[1][1] + FourbyFour[2][2] + FourbyFour[3][3]);

cout << endl;
cout << "Diagonally, the sum of the numbers is  " << sum << "." << endl;
cout << endl;

return 0;
}

Tuesday, October 28, 2014

Drivers licence exam C++

/////////////////////////////////////////////////////////////////////////////////////////////////
// Author:Joe Student                                               //
//                                                                                                      //
// Date:                    09/06/14    34                                                  //
// Program Description:Write a program that grades the written   //
//portion of the driver's license exam.                                            //
//                                                                                                     //
// Input:  Answers (A,B,C,D)                                                        //
// Processing:   Compared to prepared answer bank                     //
// Output: Number wrong, number right , pass/fail                       //
///////////////////////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <cctype>
using namespace std;
void checkAnswers(char[], char[], int, int);
int main() {
    const int NUM_QUESTIONS = 20;
    const int MIN_CORRECT = 15;
    char answers[NUM_QUESTIONS] = {'B', 'D', 'A', 'A', 'C','A', 'B', 'A', 'C', 'D','B', 'C', 'D', 'A', 'D','C', 'C', 'B', 'D','A'};
    char stu_answers[NUM_QUESTIONS];
    //Loop for users answers
    for (int replies = 0; replies < NUM_QUESTIONS; replies++) {
        cout<< "Please enter your answers (Hint: Use capital letters): "
            << (replies + 1) << ": ";
        cin >> stu_answers[replies];
        //Validation of users answers
        while (stu_answers[replies] != 'A' && stu_answers[replies] != 'B' && stu_answers[replies] != 'C' && stu_answers[replies] != 'D') {
            cout << "You must enter A, B, C, or D\n";
            cout<< "Please enter your answers (Hint: Use capital letters): "
                << (replies + 1) << ": ";
            cin >> stu_answers[replies];
        }
    }
    checkAnswers(answers, stu_answers, NUM_QUESTIONS, MIN_CORRECT);
    return 0;
}
void checkAnswers(char answers1[], char stu_answers1[], int NUM_QUESTIONS, int MIN_CORRECT) {
    //cout << "max: " << NUM_QUESTIONS;
    int correctAnswers = 0;
    //Check the student's replies against the correct answers
    for (int i = 0; i < NUM_QUESTIONS; i++)  {
        if (answers1[i] == stu_answers1[i])
            correctAnswers++;
    }
    //Did they pass or fail?
    cout << "\n\n\n\n\n\n\n\n\nYou must have at least 15 correct to pass.";
    cout << "\n-------------------------------------------";

    if (correctAnswers >= MIN_CORRECT) {
        cout << "\nStudent passed the exam";
       cout << "\n---------------------------\n\n\n\n\n";

    }
    else {
        cout <<"\nStudent failed the exam";
       cout << "\n---------------------------\n\n\n\n\n";

    }
    //Display a list of the questions that were incorrectly answered.
    cout << "The list below shows the question numbers of the incorrectly";
    cout << " answered questions.\n";
    for (int i = 0; i < NUM_QUESTIONS; i++)  {
        if (answers1[i] != stu_answers1[i])
            cout << "Question # " << i << " is incorrect." << endl;
    }
    //Display the number of correct and incorrect answers provided by the student.
    cout << "\nCorrect Answers = " << correctAnswers << endl;
    cout << "Incorrect Answers = " << NUM_QUESTIONS - correctAnswers << endl;
}

Monday, October 13, 2014

Simple Write your name in ASCII C++



///////////////////////////////////////////////////////////////////
// Author:Zachary //
//                                                               //
// Date: 08/21/2014                                              //
// Program Description: Write a C++ program using output         //
//statements (cout) to print the first three letters of your     //
//first name in big blocks. This program does not read anything  //
//from the keyboard.                                             //
//Each letter is formed using 7 rows and 5 columns using the     //
//letter itself.                                                 //
//                                                               //
// Input:                                                        //
// Processing:                                                   //
// Output:                                                       //
///////////////////////////////////////////////////////////////////
#include <iostream>

using namespace std;

int main()
{
    cout << "ZZZZZ  DDDDD SSSSS" << endl;
    cout << "    Z  D   D S    " << endl;
    cout << "   Z   D   D S    " << endl;
    cout << "  Z    D   D SSSSS" << endl;
    cout << " Z     D   D     S" << endl;
    cout << "Z      D   D     S" << endl;
    cout << "ZZZZZ  DDDDD SSSSS" << endl;
    return 0;
}

Internet Service Provider C++

/*
 * isp.cpp
 *
 *  Created on: Sep 24, 2014
 *      Author: Zach
 */

#include "isp.h"
#include <iostream>
using namespace std;

int main ()
{
int choice;
int hours;
double total;

double A = 9.95;
double B = 14.95;
double C = 19.95;
double D = 2.00;
double E = 1.00;

//Display
cout << " \t\What is your package subscription \n";
cout << "1. A.$9.95 per month. 10 hours access. Additional Hours are $2.00\n";
cout << "2. B.$14.95 per month. 20 hours access. Additional hours are $1.00\n";
cout << "3. C.$19.95 per month. Unlimited access.\n";
cout << "Enter your choice: ";
cin >> choice;

if (choice >=1 && choice <=3)
{
cout << "How many hours were used?  ";
cin >> hours;
switch (choice)
{
case 1:
{
total = A + (hours - 10)*D;
break;
}
case 2:
{
total = B + (hours - 20)*E;
break;
}
case 3:
{
total = C;
break;
}

default:
cout<<"You enter a wrong value!"<<endl;
cout << "The valid choices are 1 through 3. \n Run the program again.";
}

cout << "Your charge for this month is: $ "<<total<<endl;
}
else if (choice !=3)
{
cout << "The valid choices are 1 through 3. \n Run the program again.";
}
return 0;
}