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.

Tracing Exercises

Walk through these exercises and complete them as a group.

cpp/cs102/practiceLab3/assignExpr1

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

cpp/cin/yards-feet
cpp/cs102/practice5/computingPie

HW3 and Open-ended Help

Any students with questions about HW3 or other content may ask at this time.