Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Course: COSC 1435
- //Lab #: 7
- //Date assigned: Oct 6 2010
- //Date due: Oct 12, 2010
- //
- //Purpose: The purpose of this assignment is to create a customer invoice
- //
- //Input: Keyboard input for the
- // customer’s first and last names
- // length, width and height of a “flat-rate” box
- //
- //Output: Screen output for the
- // customer’s full name, last name first
- // dimensions of the box
- // base area and the volume and surface area of the box
- // set rate according to size
- // price of the box (rate * surface area)
- //
- //Program outline:
- // Prompt the user and enter the customer’s first name and last name.
- // Prompt the user and enter the length, width and height of the box.
- // Calculate the area of the base of the box.
- // Calculate the volume of the box.
- // Calculate surface area.
- // chose rate based on size
- // calculate price by rate * surfacearea
- /* this was compiled at home on a windows based system, so i had to slightly
- change somethings, i included the source code and my compiled executable. */
- #include <iostream>
- #include <iomanip> // reqd for setw
- #include <string> // Required for the string class.
- using namespace std;
- int main()
- {
- float length, width, height, area, volume, price, area1, area2, area3, surfacearea, rate;
- const double rate1=.026 , rate2=.028 , rate3=.030, rate4=0.32;
- /*Because we need to deal with decimals, an int or double won't work. It needs
- to be a float.*/
- char str[100]; /*A string is an array of chars, with a null 0 at the end
- so, in order to use cin.get, I had to switch to its real type.*/
- cout << "Enter customer name (lastname first) : ";
- cin.get(str,99);
- /* We were only getting up to the space. using .get, it will fetch
- the whole string for us.*/
- fflush(stdin);/* Since this is compiled in dev-cpp win7
- We need to clear our input buffer
- before we can get more input, otherwise
- our previous input will be used agian.
- Even if it allowed a second input, we'd
- be looking at a stack overflow error.
- Keep in mind, fflush() is not a standered call. In Unix im not sure if this is neccessary
- but maybe
- void clear_kb(void)
- {
- char junk[255];
- fgets (junk,255,stdin);
- . */
- cout << "What is the length of the box in inches? ";
- cin >> length;
- fflush(stdin);
- cout << "What is the width of the box in inches? ";
- cin >> width;
- fflush(stdin);
- cout << "What is the height of the box in inches? ";
- cin >> height;
- fflush(stdin);
- // cout << "What is price of shipment? ";
- // cin >> price;
- // fflush(stdin);
- volume = length * width * height;
- area1 = length * width, area2 = length * height, area3 = width * height;
- surfacearea = (2 * area1 + 2 * area2 + 2 * area3);
- if (surfacearea <= 1000)
- rate = rate1;
- else if (1000 < surfacearea && surfacearea <= 2000)
- rate = rate2;
- else if (2000 < surfacearea && surfacearea <=3000)
- rate = rate3;
- else if (3000 > surfacearea)
- rate = rate4;
- /* area1 = length * width ,area2 = length * height ,area3 = width * height ;
- lenght * width = area1 is the wrong format in programming. the destination (for lack
- of a better term is always on the left.
- area = (2 * area1) + (2 * area2) + (2* area3) for calculating total surface area ;*/
- area = length * width;
- cout << "CUSTOMER INVOICE" << endl;
- cout << "\nCUSTOMER NAME: " << str << endl; /*Escape sequences */
- cout << " " <<endl;
- cout << "BOX SPECIFICATIONS" <<endl;
- cout << " " <<endl;
- cout << "length :" << setw(8) << length<< " inches" << endl;
- cout << "width :" << setw(8) << width << " inches"<< endl;
- cout << "height :" << setw(8) << height << " inches"<< endl;
- cout << " " <<endl;
- cout << "BOX CHARACTERISTICS" << endl;
- cout << " " <<endl;
- cout << setprecision(2) <<fixed;
- cout << "base area :" << setw(10) << area << " square inches"<< endl;
- cout << "volume :" << setw(10) << volume <<" cubic inches" << endl;
- cout << "surface area :" << setw(10) << surfacearea <<" square inches"<< endl;
- cout << "price is :" << setw(10) << surfacearea * rate << " U.S Dollars" << endl;
- getchar(); /*getchar requires the user press enter before closing. Allows
- those of us running windows to be able to see the information.
- Can be removed if needed.*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement