Assignment For Prograning C++

profileshreekmarley
assignment_1.pdf

ti4(> I Chapter 9; Records (til 1 n i l s)

PROGRAMMING E X E R C I S E S

1. Assume the definition of Exercise 4, which defines the s t r u c t ftv Write a progtam that declares a variable of type fruitType, prr user to input date about a fruit, and outputs drie ftuit data.

2. Write a program that reads students' names followed by their test 5, program should output each student's name follovifed by the test u the relevant grade. It should also find and print the highest test scotr name of the students having the higjbest test score. Stutknt date should be stored in a struct variable of type studtt which has four components: studentFName and studentLName string, testScore of type int (testScore is between 0 and 10 grade of type char. Suppose that die class has 20 students. Use an a components of type studentType- Your program must contein at least the following fimctions: a. A fimction to read the students' date into the array. b. A fimction to assign the relevant grade to each student. c. A fimction to find the highest test score. d. A fijncrion to print the names of the students having the hi

score. Your program must output each student's name in this form: la« followed by a comma, followed by a space, followed by the first na" name must be left justified. Moreover, other than declaring the varia opening the input and output files, the function main should only collection of ftinction calls.

3. Define a struct, menuItemType, with two components: menult type Bt:ring and menuPrice of type doubla.

4. Write a program to help a local resteurant automate its breakfiuit system. The program should do the fijllowing: a. Show the customer the difierent breakfist items offered by the resMV b. Allow the customer to select more than one item fiom the menu, c. Calculate and print the bill.

Assume that the restaurant offers the following break&t items (the of each item is shown to the right of the item): P l a i n Egg $1.45 Bacon and Egg S2.45 Muffin $0.99 French Toast $1.99 F r u i t Basket $2.49 Cereal $0.69 Coffee $0.50 Tea SO.7R

Programming Exercises I 647

Use an array, menuList, of the struct meauItsoType, as defined in Programming Exercise 3. Your program must contain at least the following fimctions: • Function getData: This function loads the data into the array

menuList. • Function showMenu: This fimction shows the different items

ofiered by the restaurant and tells the user how to select the items. • Function printchecfc This fimction calculates and prints the check,

(Note that the biOing amount should include a 5% tax.) A sample output is: Helcome to Johimy's Restaurant Bacon and Egg S2.45 Muffin $0.99 coffee $0.50 Tax $0.20 Amount Due $4.14

Format your ouq>ut with two decimal places. The name of each item in the output must be left justified. You may assume that the user selects only one item of a particular type.

5. Redo Exercise 4 so that the customer can select multiple items of a particular type. A sample output in this case is:

Melcome to Johnny's Restaurant 1 Bacon and Egg $2.45 2 Muffin $1.98 1 Coffee SO.50

Tax $0.25 amount Due $5.18

S. Write a program whose main fimction is merely a collection of variable declarations and fimction calls. This program reads a text and outputs the letters, together with their counts, as explained below in the fimction printResult. (There can be no global variables! All information must be passed in and out of the fimctions. Use a structure to store the information.) Your program must consist of at least the following fimctions: • Function openFile: Opens the input and output files. You must pass the

file streams as parameters (by reference, of course). If the file does not exist, the program should print an appropriate message and exit. The program must ask the user for the names of the input and oû ut files.

• Function coimt: Counts everv occurrence nf ranî i) If-fton a_"7