Beruflich Dokumente
Kultur Dokumente
Page 11, Exercises 1.1 #1 (a-q), #2, #3 (Written definitions and answers) Page 17, Exercises 1.2 #1 Page 21, Exercises 1.3 #2, 3 (write out programs on paper) Page 25, Exercises 1.4 #2a, 2b
Due Aug 22 Chapter 2 (Data Types, Dec) Assignments: (All should be written on paper to be turned in)
Page 47, Exercises 2.1 #1, 7, 8, 9 Page 55, Exercises 2.2 #1, 2, 4 Page 66, Exercises 2.3 #1, 2, 3, 5, 10
class Food { private: float hamburgers; //price for hamburgers float fries; float sodas; int num_ham; //number of hamburgers int num_fries; int num_sodas; public: Food(); //Constructor to set defaults prices void getdata( ); void calculate( ); void displaydata( ); };
Food::Food( ) { hamburgers = 1.50; fries = .75; sodas = 1.00; num_ham=0; num_fries=0; num_sodas=0; }
//Default values set //Values can be changed in any member functcion //Values can be used in any member function
void Food::getdata( ) //getadata function of the Food class { cout<<"How many hamburgers?"<<endl; cin>>num_ham; cout<<"How many fries?"<<endl; cin>>num_fries; cout<<"How many sodas?"<<endl; cin>>num_sodas; } void Food::calculate( ) //No need to send data into function, Class has access to data { hamburgers = num_ham * hamburgers; //Price for hamburgers is price times # of hamburgers fries=num_fries * fries; sodas = num_sodas * sodas; }
void Food::displaydata() { system ("cls"); //clearscreen cout<<setiosflags(ios::fixed)<<setprecision(2); cout<<"Hamburgars: $"<<hamburgers<<endl; cout<<"Fries $"<<fries<<endl; cout<<"Sodas $"<<sodas<<endl<<endl; cout<<"Total is $"<<(hamburgers + fries+sodas)<<endl; } int main () { system("cls"); cout<<"WELCOME TO THE GREASY SPOON"<<endl<<endl; Food f1; int choice=1; //Declare an instance of the class
while (choice !=4) { cout<<endl<<endl; cout<<"Please type in a number of your choice"<<endl<<endl; cout<<"1. Place an order "<<endl; cout<<"2. Calculate your total "<<endl; cout<<"3. Display your total "<<endl; cout<<"4. Exit the program"<<endl; cout<<endl<<endl; cin>>choice; if (choice ==1) f1.getdata(); if (choice ==2) f1.calculate(); if (choice ==3) f1.displaydata(); } system ("pause"); return 0; }
//Call function