Week 3 Lab
Sign in to lab!
Any remaining Vocareum login issues?
Let your CP/TA know.
Q&A on Material
- Remaining questions on variables, types, expressions.
cin
,cout
- Integer and doubles, expressions involving both
- Assignment and sequencing of operations
Homework Style Guide
As you begin HW3, remember roughly 20% of your score is based on visual inspection of your code for style (indenting and comments). See the style guide for directions on indenting and commenting.
Also, remember that you can submit as many times as you like on Vocareum and that you should ALWAYS review the submission report that is generated to determine if your output matches our desired format and expected values. Carefully, review the report and make any updates to your code to fix discrepancies.
Tracing Exercises
Walk through these exercises and complete them as a group.
Trace through (manually predict) what this program will output when executed by tracking the value of each variable at each step. You can always copy the code into Vocareum or cpp.sh to see the correct output, but do so only after you have worked through it by hand.
#include <iostream>
using namespace std;
int main()
{
int odometerBefore = 150056;
double gasInTank = 8.0;
double initialGas = gasInTank;
double mpg = 40.0; // a reasonable hybrid car
int odometerAfter = 150106;
gasInTank = gasInTank - (odometerAfter - odometerBefore) / mpg;
cout << "Started with " << initialGas << " gallons." << endl;
cout << "Ended with " << gasInTank << " gallons." << endl;
gasInTank = gasInTank + 5.7;
cout << "Fueled up to " << gasInTank << " gallons." << endl;
return 0;
}
Cin and Expressions Exercises
HW3 and Open-ended Help
Any students with questions about HW3 or other content may ask at this time.