I'm currently in a class for C++. I just took a midterm, and I thought all my answers were very good, but some didn't get any points. I just wanted to find out what I did that was wrong about them, not to doubt my teacher, but to just know how I got my answer wrong.
The first one that I got wrong was:
Using three different rules for creating valid variable names, make up an example for each that would NOT compile.
My answer was:
int ex ample int 2example char cout
Here I'm assuming its the Char, I feel as though I should have called a different variable.
2. (This ones a longer one)
What is the EXACT output of the following program given that the user enters the following inputs:
P Maria Lucelli 1000
char status; string name1; string name2; int amount; cout << "What is the customer’s status ?"; cin >> status; if (status == 'P') cout << "Preferred customer, eligible for gold card."<<endl; else cout << "Regular customer."<< endl; cout << "Enter full name :"; cin >> name1 >> name2; cout << "Thank " << name1 << " for his/her business" << endl; if (status == 'P') { cout << "Ask how much to transfer to 2.9 %"; cin >> amount; if (amount > 1000) cout << "This may take a moment to verify."; } else cout << "Have a nice da y.";
My answer was:
What is the customers status? P preferred customer, eligible for gold card. Enter full name: Maria Lucelli Thank Maria for his/her business Ask how much to transfer to 2.9% 1000 have a nice day.
I literally copied it letter by letter. I really would like to know what I did wrong for this one.
3.
Write a block of code that demonstrates the concept of overflow.
My answer was:
int a;
a=INT_MAX;
cout<<a+5;
When I ran this, it overflowed to a negative number and yadda yadda. Could I have misunderstood what overflow means?