Taking a C++ Class...You?
Just wondering if anyone else is taking a required C++ class like I am. If you are I would love to hear some horror stories about professors, programs, etc. Mine is a cool guy with a lot of energy but is a crazy stickler on the details!
One of his quirks is how he wants code to be lined up. When you declare variables he wants you to initialize them when they are declared vs after. Example:
I realize that this looks better and is a little less code to write but what confuses me is when later he has us code our lines like this:
Instead of something like this:
That and the book we are using clearly says that the escape sequence for the "Return" or "Enter" key is:
Whereas he grades it like so:
Which of course is a newline. (I can see his logic...but the book says otherwise!) Oh well. Just wanted to share that and my 2nd program.
Spacing got messed up and I'm too lazy to fix it since no body cares anyway:P
One of his quirks is how he wants code to be lined up. When you declare variables he wants you to initialize them when they are declared vs after. Example:
Code:
//WRONG! int oranges; oranges = 100; //CORRECT int oranges = 100;
Code:
cout << left << setw(16); cout << "Regular Price "; cout << right << setw(5) << "$"; cout << right << setw(9) << regularPrice; cout << endl;
Code:
cout << left << setw(16) << "Regular Price "; cout << right << setw(5) << "$"; cout << right << setw(9) << regularPrice << endl;
Code:
/r
Code:
/n
Spacing got messed up and I'm too lazy to fix it since no body cares anyway:P
Code:
// STUDENT CODE BEGINS
//preprocessor directives
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
/* data section */
//declared and initialized variables
double regularPrice = 0.0;
double discount = 0.0;
double salePrice = 0.0;
/* statements section */
//program headings
cout << "Project: U02_EnterPrice" << endl;
cout << "by" << endl;
cout << "*** you" << endl;
cout << endl << endl;
/* INPUT */
//enter input
cout << "Enter the Regular Price " << endl;
cin >> regularPrice;
cout << endl;
/* PROCESSING */
//calculate the discount
discount = regularPrice * 0.2;
//calculate the sale price
salePrice = regularPrice - discount;
/* OUTPUT */
cout << fixed << showpoint << setprecision(2);
//display the regular price
cout << left << setw(16);
cout << "Regular Price ";
cout << right << setw(5) << "$";
cout << right << setw(9) << regularPrice;
cout << endl;
//display the discount amount
cout << left << setw(16);
cout << "Discount amount ";
cout << right << setw(5) << "$";
cout << right << setw(9) << discount;
cout << endl;
//display the final save price
cout << left << setw(16);
cout << "Save Price ";
cout << right << setw(5) << "$";
cout << right << setw(9) << salePrice;
cout << endl;
/* program termination section */
cin.ignore();
cin.get();
return 0;
//end of main function
}
// STUDENT CODE ENDS



