Sunteți pe pagina 1din 5

Fresno City College

Dr. Joan Frese

C++ Homework Assignments, Fall, 2013


Chapter 1 Due Aug 15 (Getting Started) Assignments:
(All should be written on paper to be turned in)

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

Due Aug 29 Chapter 3 (Assignment & Input) Assignments:


Turn in the programs on a USB in a manila envelope. Save the programs as: 3_1Num1, 3_1Num2, etc. All programs must have a remark statement with your name and the program number. All programs must display answers. Put written on a paper in envelope (6 Programs total) Page 90; Exercises 3.1 #1, 2, 3. Write all 3 of these as programs instead of writing just an assignment statement. For Program #1 calculate the circumference with a radius of 3.3; For program #2 calculate area where radius is 5; For program #3 calculate Celsius where Fahrenheit is 98.6. Page 112; Exercises 3.3 #2 (written) Page 122; Exercises 3.4 #2, 3, 4 For #4 you dont need to complete the chart.

Due Sep 5 Chapter 4 (Selection) Assignments:


Page 142; Page 154; Page 163; Page 172; Exercices 4.1 #1, 2, 4 (Written) Exercices 4.2 #4, 6, 10, 16 (4 programs on disk) Exercices 4.3 #2, 4 (2 programs on disk) Exercises 4.4 #4 Modify program 4.4 on page 160 to a switch statement and put in a complete running program (1 program on disk)

Due Sep 12 Chapter 5 (Repetition) Assignments (4 programs):


Page 186; Exercises 5.1 #2 (Rewrite program 5.4 pg. 185), 4, 6 (3 programs on disk) Page 198; Exercises 5.2 #2 (Modify Program 5.6 on pg. 192 and save program),

Due Sep 19 Chapter 6 (Functions) Assignments:


Page 241; Exercises 6.1 #2, 10 (Functions return void) (2 programs - USER enters data) Page 254; Exercises 6.2 #2 a, b, c, d (written) 3, 6, 7 (3 programs - USER enters data) Page 266; Exercises 6.3 #4 - User enters $ amount, function should return VOID Page 283; Exercises 6.5 #1, 2 (Written)

Due Sept 26 Chapter 7 (Arrays) Assignments:


Page 300; Exercises 7.1 #2, 6a, 8a, 11 (#2 written on paper, 6,8,11, programs) Note: #6 , 8, & 11 USER inputs the numbers (may not be same as in book) Page 306; Exercises 7.2 #4, 7 (#4 user does not input prices, only units, dont fill in chart; #7- Just prints the messages) Page 312; Exercises 7.3 #4b (Modify program on page 308), 6a

Due Oct 3 Chapter 14 (Strings) Assignments:


Page 621; Exercises 14.1 #1 Enter the program on page 610, #2 (written), #3 Enter program on pg. 617 and modify so user can enter any string, # 8 Enter program on pg. 619-620 Page 633; Exercises 14.2 #3 (program)

Due Oct 10 Chapter 15 (Strings as Char Arrays) Assignments:


Page 689; Exercises 15.2 #1 (written) Page 697; Exercises 15.3 #1 (written) Write a program that that counts the number of characters including spaces in a string, not including the null. Dont use the strlen function write your own function. Save as: 15_1 Write a program that lets the user input two messages. Concatenate the second message onto the first (add the second message to the end of the first message) Save as: 15_2 Write a program that has the user input a message. The program should find the length of the message and then in a for loop one by one change each character to uppercase. Print out the message in all caps. Save as: 15_3

Due Oct 17 Windows based Applications (Handout)


5 Exercises from handout. Turn in program on USB and also a printout for each Name the programs Ex1, Ex2, Ex3, etc.

Due Oct 24 Chapter 8 (Pointers) Assignments


Page 351; Exercises 8.1 #1, 2, 3a (written) Page 363; Exercises 8.2 #1a,b,c; #2 a,b,c, #3 a,b (written) #4a,b (2 separate programs) Page 368; Exercises 8.3 #3 a, b; (2 programs) 3b for(messPt++) Write a program that allows the user to input any number of grades. Have the program print out each element of the array (each grade), the total and average. Prints Your grades are:, The total is: Average is:

Due Oct 31 Chapter 16 (Structures) Assignments:


Page 707; Exercises 16.1 #1 a, b; #2 a. Declare structure, initialize in separate statements #2 b. Declare and initialize in all at once #4 Program on disk (Use a loop to get data) Page 710; Exercises 16.2 #2, #4 (2 Programs on disk). On #4 even though the book shows you a chart of names and numbers, your program should let the user enter the data so that any names and numbers can be entered. Display in a table format.

Due Nov 7 Chapter 10 (Classes) Assignments:


Page 449 10.1 #1 a - l (Written) Do the attached programs : 1. Employee, 2. Employee_Array, 3. Student 4. Fastfood 1. Save as : Employee Declare a class named Employee Data : name payrate hours totalpay Functions : getdata calculate total pay display Create ONE object of this clas and call all the functions 2. Save as : Employee_Array Using the class above, declare an array of 3 employees of the class Employee Using a loop, call the getdata and calculate functions Using a loop, call the display function to show a table of 3 employees and their total pay 3. Save as : Student Declare a class named Student Data : name id grades[3] totalgrades Functions : getdata calculate average of grades display Declare an array of 4 students. Use loops to enter the data, calculate the grade averaaage, and display a table with all the students and their grade averages 4. Type the attached program (Fast Food Program). Make sure it is running properly. /**************************** Fastfood Program Example of a Class in C++ Your Name ****************************/ #include <iostream> #include <iomanip> using namespace std;

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

Due Nov 14 Chapter 9 Assignments:


Write a program that allows the user to enter some items of data and save it to disk and then display it on the screen. It should let the user enter as many items as they want. (Similar to the programs shown in class where there is a menu that allows user to enter employee names or inventory items - the menu is in a loop so user can keep entering more names or items or display the items). You MUST use a class for this program

S-ar putea să vă placă și