CSCI 159 Quiz 1 (Wednesday section)

The quiz is open notes, open book, and you are permitted to use your linux accounts to write/check practice code if desired. For example, you could use the following to edit, compile, and check code in a quest1.cpp file:
    gedit quest1.cpp &
    g++ quest1.cpp -o quest1x
    ./quest1x
There are four questions, two on each side of two pages, and you have 60 minutes to complete the quiz.
The quiz must be completed as a completely individual exercise: you cannot request or accept help from any other source (human or ai) other than the course instructor, and you cannot give help to anyone else for the quiz.
If you finish early you can leave or stay and work quietly while others finish their quizzes.

Question 1: basic code functionality

Assume the code below is embedded in a main routine and the iostream library has been included.

If the user enters values 3.2 then 0.6 when prompted, the code segment below would display 4.8 as the final result.

Explain how it arrives at that answer, showing the values of the variables each time they change through the run of the code segment.
   double baseValue, increment, fineTune, total;
   baseValue = 2.5;
   increment = 10;
   fineTune = 1.0;

   total = baseValue + increment;

   std::cout << "Enter a base value (e.g. 99.9): ";
   std::cin >> baseValue;

   total = baseValue;

   std::cout << "Enter an increment value (e.g. 6.7): ";
   std::cin >> increment;

   total = baseValue + increment;
   total = total + fineTune;

   std::cout << "The final total is " << total << std::endl;

Question 2: code standards

In your own words, briefly explain the purpose of code standards and they help in developing and maintaining code.

Question 3: using functions and parameters

Assuming that (1) Write one single line of code that calls the pow function to compute AB and store the result in C.

(2) Write a second line of code that displays C's value in a column 18 characters wide. (Don't worry about setting any fixed precision, just the column width.)

(3) For the two lines of code you wrote, explain which values are parameters and, just for the pow call, what what constitutes the 'return value'.

Question 4: functions and design

In your own words, briefly explain how the use of functions can help us to design and maintain larger and larger programs.