CSCI 102 - Fall 2023 Fundamentals of Computation

Week 3 Lab

Sign in to lab!

Any remaining Vocareum login issues?

Let your CP/TA know.

Q&A on Material

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

cpp/cs102/practiceLab4/assignAndIncDec

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

cpp/cs102/lab4/root-solver
cpp/cs102/practiceLab4/apy
cpp/cs102/practice5/computingPie

Casting Exercises

cpp/cs102/practice5/messageDecoder

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:

cpp/division-modulo/kilograms

Open-ended Help

Any students with questions may stay after to get help. Please ask questions! Anyone else may leave at this stage.