CMPT 130 Lab 1 - Division

 

In this lab you are going to create a program that performs some calculations and prints the results in a sensible format.  You should use a Linux text editor and the Terminal to create and run your program.

 

Labs are assessed so make sure that the TA has seen, and marked, your finished work before you leave the lab.

 

Output

Your program should prompt the user to enter two numbers and calculate the quotient and remainder of the first divided by the second.  Look at the sample program in the second presentation to get some help with input and output (page 12).

 

Your output should be similar to the sample shown below.

 

Enter the dividend: 113

Enter the divisor: 10

113 divided by 10 = 11 remainder 3

 

Information You May Need to Know

The % operator can be used to calculate the remainder, e.g. 13 % 4 = 1 (since the result of 13 divided by 4 is 3 remainder 1).

 

Compiling and Running your Program

 

To compile your program open the terminal (after saving your text file as something like lab1.cpp) and run gcc.  Assuming that you called your file lab1.cpp then you should run g++ -o lab1 lab1.cpp in terminal.

 

To run your program enter the command ./lab1 in terminal.

 

Playing with your Program

 

Once you've got your program working run it a few times with different values to make sure that it always returns the correct result.  Then see how robust it is by trying to give it input that it can't handle (but at this point you don't have to worry about fixing any errors that invalid input causes).

 

Assessment

1 mark for completion of the lab.

 

 

CMPT 130 Home

 

John Edgar (johnwill@sfu.ca)