Taking a C++ Class...You?

Posts 1–15 of 15 · Page 1 of 1
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:

Code:
//WRONG!
int oranges;
oranges = 100;

//CORRECT
int oranges = 100;
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:

Code:
   cout << left << setw(16);
   cout << "Regular Price ";


   cout << right << setw(5) << "$";
   cout << right << setw(9) << regularPrice;
   cout << endl;
Instead of something like this:

Code:
   cout << left << setw(16) << "Regular Price ";


   cout << right << setw(5) << "$";
   cout << right << setw(9) << regularPrice << endl;
That and the book we are using clearly says that the escape sequence for the "Return" or "Enter" key is:

Code:
/r
Whereas he grades it like so:

Code:
/n
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
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
Quote Originally Posted by Necc View Post
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:

Code:
//WRONG!
int oranges;
oranges = 100;

//CORRECT
int oranges = 100;
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:

Code:
   cout << left << setw(16);
   cout << "Regular Price ";


   cout << right << setw(5) << "$";
   cout << right << setw(9) << regularPrice;
   cout << endl;
Instead of something like this:

Code:
   cout << left << setw(16) << "Regular Price ";


   cout << right << setw(5) << "$";
   cout << right << setw(9) << regularPrice << endl;
That and the book we are using clearly says that the escape sequence for the "Return" or "Enter" key is:

Code:
/r
Whereas he grades it like so:

Code:
/n
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
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

Not bad for a beginner
Quote Originally Posted by Necc View Post
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:

Code:
//WRONG!
int oranges;
oranges = 100;

//CORRECT
int oranges = 100;
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:
There's another reason for initializing your variables when you declare them. Some of the can give you really weird numbers if you don't initialize them first, especially out of scope. I think double you get some weird negative number, int works.

So if you declared
Code:
int oranges;
without initializing it and you tried to
Code:
 cin >> oranges;
from the user and the user didn't give you an EXPECTED number, you're gonna end up with some really weird number. (orange could be -8.4million and now you're gonna mulitple this by the cost and get a massive negative number...)
dont use using namespace std; it's a bad style and can also cause huge Errors...
Quote Originally Posted by bloodx_ View Post
dont use using namespace std; it's a bad style and can also cause huge Errors...
It's something your teacher wants you to do when you start out. I'm also taking a Computer Science class and we're also doing C++.
Quote Originally Posted by bloodx_ View Post
dont use using namespace std; it's a bad style and can also cause huge Errors...
std:: anyone?
if your working for example with socket's you get a error :-D

just dont use global namespace's ... std:: is no problem at all or ?
Quote Originally Posted by bloodx_ View Post
dont use using namespace std; it's a bad style and can also cause huge Errors...
Style? uwotm8?

When you have multiple namespaces and if you're just including all their functions without the access operator then they could collide.

Quote Originally Posted by bloodx_ View Post
if your working for example with socket's you get a error :-D

just dont use global namespace's ... std:: is no problem at all or ?
Huh? Not working with sockets?



Proof.

The rule is as stated above :

Two namespaces that contain the same function could collide and you could turn up calling the wrong function.
Quote Originally Posted by Hitokiri~ View Post


std:: anyone?
jajajajajaja
Quote Originally Posted by Knochove View Post
Quick question: Why are you including winsock2.h ?

Disable lean&mean and windows.h includes it for you.
:/
Quote Originally Posted by InunoTaishou View Post
There's another reason for initializing your variables when you declare them. Some of the can give you really weird numbers if you don't initialize them first, especially out of scope. I think double you get some weird negative number, int works.

So if you declared
Code:
int oranges;
without initializing it and you tried to
Code:
 cin >> oranges;
from the user and the user didn't give you an EXPECTED number, you're gonna end up with some really weird number. (orange could be -8.4million and now you're gonna mulitple this by the cost and get a massive negative number...)
It's not like I'm not initializing it, its just that I'm not initializing it on the same line as when i declare it...even in some of his example code he has something like this:
Code:
/* declarations ***********************************************      declare function data
   */
   double checkAmount;                 // amount of a single check
   double allChecks;                   // amount of all checks
   int checkCount;                     // number of checks processed


   string choice;                      // program loop control




   /* statements *************************************************
      code function instructions
   */


   // set the program loop identifier
   allChecks = 0;                      // totals always set to 0
   checkCount = 0;                     // counters always set to 0
Or even worse:
Code:
 double test1, test2, test3, test4, test5;
 double average;
 double length,   // The crate's length
          width,    // The crate's width
          height,   // The crate's height
          volume,   // The volume of the crate
          cost,     // The cost to build the crate
          charge,   // The customer charge for the crate
          profit;   // The profit made on the crate
Both of which go completely against his own teaching. But what do I know, I'm totally white to it.

Quote Originally Posted by bloodx_ View Post
dont use using namespace std; it's a bad style and can also cause huge Errors...
Just as @InunoTaishou, we actually have to. It's required for all class work in my case. Maybe later on if I take his advanced C++ and start using more headers than cmath, string, iomanip, and iostream it will become a problem and I will have to change
Quote Originally Posted by Hitokiri~ View Post


Quick question: Why are you including winsock2.h ?

Disable lean&mean and windows.h includes it for you.
:/
That was copypasta from MSDN so I could prove my point.
also did you mess arround for example with bind ?

sure you can do it if you really want it, but why ? it's still not there of using it like this...
Quote Originally Posted by Necc View Post
But what do I know, I'm totally white to it.
So then being black to it implies you're 1337?

Necc4Racist2k15
Quote Originally Posted by Hitokiri~ View Post

So then being black to it implies you're 1337?

Necc4Racist2k15

Exactly. Jk, I never heard of being black to anything.

And I'm not racist, I'm dating a mexican and I have a colored tv.


Spoiler tags don't work?

Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us