Week 4 Lab
Sign in to lab!
Q&A
+=
/-=
syntax- Increment and Decrement operators
- Implicit/Explicit casting (why do we need the latter?)
- setprecision, fixed, and other I/O manipulators
Review Math Functions and Casting
Trace the execution of this program and predict what this program will output.
cpp/cs102/practiceLab4/assignAndIncDec
Again, 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, Cassting, and Library Function Exercises
cpp/cs102/lab4/root-solver
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 (your instructors will select a subset of these exercises and you can try the others on your own):
cpp/division-modulo/kilograms
cpp/division-modulo/birth-year
cpp/division-modulo/middle2
HW 4 Q&A
Open-ended discussion of issues and general concepts related to HW4
More Practice Problems
Perform these on your own for more practice.
Expressions, Casting, and Library Function Exercises
cpp/cs102/practiceLab4/apy
cpp/cs102/practice5/messageDecoder
Division and Modulo
cpp/division-modulo/convert
cpp/division-modulo/sections
Open-ended Help
Any students with questions may stay after to get help. Please ask questions! Anyone else may leave at this stage.