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.
- Increment and Decrement operators
+=
/-=
syntaxcin
,cout
- Implicit/Explicit casting (why do we need the latter?)
- setprecision, fixed, and other I/O manipulators
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.
Exercises
Walk through these exercises and complete them as a group.
Tracing
Trace the execution of this program and predict what this program will output.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int games = 16;
int tixMonday = 100;
games++;
int tixTuesday = 25;
games++;
int lateTuesday = 5;
tixTuesday += lateTuesday;
double priceMonday = 45.5;
double priceTuesday = 80.0;
double avgTixSold = (tixMonday + tixTuesday) / 2.0;
cout << "Max revenue: "
<< max(tixMonday * priceMonday, tixTuesday * priceTuesday)
<< endl;
cout << "Floor average tickets sold: "
<< floor(avgTixSold) << endl;
cout << "Int average tickets sold: "
<< (int) avgTixSold << endl;
return 0;
}
Expressions and Library Function Exercises
Casting Exercises
Idioms Related to Division and Modulo
Take a look at how to use division and modulo for the purposes of unit conversion as this will be useful in your future homework:
Now practice with this idiom:
Open-ended Help
Any students with questions may stay after to get help. Please ask questions! Anyone else may leave at this stage.