CS 010 - Introduction to Computer Science I
Lab 2.
Fundamental Data Types

Points(10 overall)


Collaboration policy:
You will be working in pairs during labs.  Pairs will be selected and announced by the TA.    You will discuss the programs with your partner, but you will still be typing in your own code to show to the TA.  You can help each other debug, give plenty of suggestions and hints, **explain** why things work or don't work, etc.


Lab Objectives

To gain experience with


Getting Ready

Commenting and Style


Step 0: Collaboration Policy Form

Collaboration Policies

Download this file, read it, and fill in the information at the bottom. You can use emacs to edit the file similarly to how you edit your programs. Turn in the edited file to the lab2 online turnin folder the same way you turned in lab 1. Get help with the turnin from your partner or the TA if you missed lab 1.

This file must be turned in with all of your information added to receive a grade on any programming assignment.


Program 1: Arithmetic Operators

Write a program that accepts 2 integer values from the user. Your program should then output the sum, the average, the product, and finally the integer quotient and remainder after dividing the first integer by the second integer. The sum, product, integer quotient and remainder should all be integers values. The average should be a floating-point (double) value.

Example 1:

   Enter the first integer: 10
   Enter the second integer: 25

   Sum: 35
   Average: 17.5
   Product: 250
   Integer quotient: 0
   Remainder: 10

Example 2:

   Enter the first integer: 15
   Enter the second integer: 5

   Sum: 20
   Average: 10.0
   Product: 75
   Integer quotient: 3
   Remainder: 0

Example 3:

   Enter the first integer: 12
   Enter the second integer: 10

   Sum: 22
   Average: 11.0
   Product: 120
   Integer quotient: 1
   Remainder: 2

Writing the Program:

If you are not inside of your lab2 directory, use the change directory command (cd lab2) to descend into that directory.  Now that you are in that directory, make another directory for the above program, maybe call it operators.  Then descend into your new directory.  Now you are ready to start writing your program.  Now you can execute the command emacs main.cpp & to start typing your program.

 


Program 2: Arithmetic Operators

Write a program to compute a student's weighted course score.  There are three tests in the class.  The user should enter the maximum points for each test (they do not have to be the same) (integer), the student's score on each test (integer), and the weight of each test (as a percent of 1.0 (0.4 = 40%)) (floating-point value).  Your code should output the student's weighted course grade.

 

Example 1:

Weight of first test: 30

Maximum on first test:  100

Score on first test:  93

 

Weight of second test: 30

Maximum on second test:  100

Score on second test:  87

 

Weight of third test: 40

Maximum on third test:  150

Score on third test:  101

 

Your overall grade is 80.93%

 

Writing the Program:

Move yourself back into the lab2 directory (to go up a directory, use cd .., to go into a directory, use cd directory_name).  If you were to do an ls here you should see your money directory.  Now make another directory for your second program, maybe call it grade.  Go into this directory and begin to write your program using emacs main.cpp &.

 


Bonus: 1 Point

One can use their age to calculate their target heart rate zone for aerobic exercise.  Write a program that takes a users age and outputs their target heart rate zone (output both the lower and upper limits as a floating-point value).  The formula to calculate the zone in beats per minute (bpm) is:

            Lower limit (bpm) = 60% of the difference between 220 and your age

            Upper limit (bpm) = 75% of the difference between 220 and your age

 

Example:

If a person’s age was 25, then their target heart rate would be between 117 bpm and 146.25 bpm.