public
anonymous / assignment.txt
Created

Program to ask students for text book cost and calculate total for unknown number of students then output a report.

  • Download Gist
assignment.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
C. Assignment:
1. This program will simulate an electronic means to calculate textbook costs for an unknown number of students for the college bookstore.
2. An output report should look similar to the following example:
 
Student Textbook Purchases Report
*****************************************************
Student Book Book Tax Book
Id Code Cost Amount Subtotal
--------- ------- ------ ---------- ----------
1111 B 80.00 ? ?
1111 C 70.00 ? ?
 
Total number of books purchased: ?
Total books cost including tax: ?
 
*****************************************************
Student Book Book Tax Book
Id Code Cost Amount Subtotal
--------- ------- ------ ---------- ----------
2222 M 40.00 ? ?
2222 S 50.00 ? ?
2222 P 90.00 ? ?
 
Total number of books purchased: ?
Total books cost including tax: ?
 
*****************************************************
Student Book Book Tax Book
Id Code Cost Amount Subtotal
--------- ------- ------ ---------- ----------
3333 E 30.00 ? ?
 
Total number of books purchased: ?
Total books cost including tax: ?
 
*****************************************************
Grand Totals:
Total number of students who purchased books: ?
Total number of books sold: ?
Total cost of all books and taxes: ?
 
*****************************************************
 
 
3. Inputs:
a. Student Id
b. Book Code
c. Book Cost
4. Output values on the report for each student:
a. Student Id
b. Book Codes
c. Book Costs
d. Tax Amount
e. Book subtotal
5. The following totals need to be calculated for each student:
a. Total number of books purchased
b. Total books cost including tax
6. The following totals need to be calculated at the end of the report after all of the student book purchases have been entered and calculated for each student:
a. Total number of students who purchased books
b. Total number of books sold
c. Total cost of all books and taxes
7. Processing events:
a. A loop will be needed to process all the data so that one report can be generated for all of the students and their purchases.
b. The total number of students who purchase books can be any number of students so the loop that is needed should be controlled by inputting a sentinel value of “-9999” for the student id to determine when the loop to process each student’s purchases should end.
c. After the loop ends, the grand totals should be printed.
d. The sales tax rate that should be used to calculate the tax cost per book is 7 percent.
textbook.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#include <iostream>
#include <iomanip>
 
using namespace std;
int main ()
{
//Declare Variables.
int student_id;
char book_code;
float book_cost;
float tax_amount;
float book_subtotal;
const int SENTINEL = -9999;
const double TAX = .07;
float total_book_cost;
int number_books;
int total_books_sold;
double grand_total;
 
//Set Variables to Zero.
number_books = 0;
total_book_cost = 0.00;
grand_total = 0.00;
 
//Set Decimal to two places.
cout << fixed << showpoint;
cout << setprecision(2);
 
//Input Data
cout<<"Please enter your Student ID, then press enter."<<endl;
cin>>student_id;
while (student_id != SENTINEL){
cout<<"Please enter your Book Code, then press enter."<<endl;
cin>>book_code;
cout<<"Please enter the cost of the book, then press enter."<<endl;
cout<<"$"; cin>>book_cost;
tax_amount = book_cost * TAX;
book_subtotal = book_cost + tax_amount;
total_book_cost += book_subtotal;
number_books++;
cout<<"\tStudent Textbook Purchases Report"<<endl;
cout<<"********************************************"<<endl;
cout<<"Student"<<"\tBook"<<"\tBook"<<"\tTax"<<"\tBook"<<endl;
cout<<"Id"<<"\tCode"<<"\tCost"<<"\tAmount"<<"\tSubtotal"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<student_id<<setw(5)<<book_code<<setw(8)<<"$"<<book_cost<<
setw(3)<<"$"<<tax_amount<<setw(4)<<"$"<<book_subtotal<<endl;
cout<<endl;
cout<<"Total number of books purchased:"<<setw(8)<<number_books<<endl;
cout<<"Total books cost including tax:"<<setw(9)<<"$"<<total_book_cost<<endl;
cout<<"Please enter your Student ID, then press enter."<<endl;
cin>>student_id;
}
grand_total += total_book_cost;
total_books_sold += number_books;
cout<<"**************************************************"<<endl;
cout<<"Grand Totals:"<<endl;
cout<<"Total number of students who purchased books:"<<endl;
cout<<"Total number of books sold:"<<endl;
cout<<"Total cost of all books and taxes:"<<setw(9)<<"$"<<grand_total<<endl;
 
//Can put grand totals here
 
system("Pause");
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.