Hello. I am taking an intro to programming course and i need help coming up with
ID: 3892079 • Letter: H
Question
Hello. I am taking an intro to programming course and i need help coming up with a psuedocode for an algorithm. Here is the assignment.
The program is for students to order books for the amount of courses being taken (one book for each course). Then asking the student if they want their books ordered for pick up or delivery (there is a delivery fee of $4.99 added to the total cost of all books).
1. Prompt student to enter their name
2. Prompt student to enter number of courses being taken
3. Read the prices of each book into an array from a file using a loop
4. Use a second loop to sum the values stored in the array after the prices of all the books have been read
5. Write the content of the array to a second file
Please write a psuedocode based on the programs needs. Thanks!
Explanation / Answer
PSUEDOCODE:
Start
1. Declare the variables SNAME, SCOURSES, FPTR1, FPRT2, PRICE[50], SUM=0,
2. Print “Enter name:”
3. Read student name and store in SNAME
4. Print “Enter number of courses:”
5. Read number of courses and store in SCOURSES
6. for(i=0;i<SCOURSES;i++)
6.a. Display books details from the file using file pointer FPTR1 and ask the student to select the required book
6.b. Store the price of selected book in PRICE[i]
7. for(i=0;i<SCOURSES;i++)
SUM = SUM+PRICE[i]
8. Write the PRICE[i] into the second file using FPTR2
9. Print “Total cost of the books:” Display SUM
10. Ask the user to select option “pick-up” or “delivery”
11. if user selects second option (delivery)
then BILLING AMOUNT = SUM+$4.99
else BILLING AMOUNT = SUM
12. Print BILLING AMOUNT
End
EXPLAINATION:
SNAME must be declared of type char or string.
SCOURSE must be of type int
FPTR1 and FPTR2 are the pointers to the files using which we can open, read, write and close the file.
PRICE[50] is an array of type float. Assuming there are no more than 50 courses for each student.
SUM is of type float. It must be initialized to 0 because in the FOR loop we are using the value of it. If we don’t initialize it then it will give junk value.
Using respective printing and reading statements of required programming language we can display the messages and read data from the user.
BILLING AMOUNT is the total cost of all books including delivery charges if applicable.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.