Sie sind auf Seite 1von 2

Qatar University

Fall 2019 CENG106: Computer Programming

Assignment #2:
Submission deadline: Sunday, November 17th, 2019

Submission Instructions:
1. In the Documents folder of your computer, create a folder called Fall2019_Homeworks_2
in which all your work should be saved. You should submit an archive of this folder when
you finish. 
2. In the Fall2019_Homeworks_2 folder, create an MS-Word document called mySolution and
add your name and QUID on the top line and save the file. You will add copies of your
source files and output screens, as well as answers that do NOT require coding, to this file.
3. Create a C++ Project named XYZ Where XYZ is your “QU Username”. 
4. Please add your name and QUID as comments on the top of each source file.
5. When you finish, save all open files, close Visual C++, close MS-Word, and then archive your
Fall2019_Homeworks_2 folder as a .rar file and upload it on Blackboard.
6. Please note that readability of your code is very important. Using meaningful identifier
names for your variables, in addition to maintaining correct source code formatting is
graded as part of your solution.  
Feel free to seek assistant from your lab instructor/TA on this, if needed.

Q1. Given the following fragment that converts from a Celsius degree to a Fahrenheit degree.
double c = 20; double f;
f = (9/5) * c + 32.0;
a) What value will be assigned to f?
b) Explain what is actually happening, and what the programmer likely wanted.
c) Rewrite the code as the programmer intended.

Q2. The area of a rectangle is the rectangle’s length multiplied by its width. Write a program
that asks for the length and width of two rectangles. The program should tell the user which
rectangle has the greater area, or if the areas are the same.
Q3. Write a program that calculates and displays a person’s body mass index (BMI). The BMI is
often used to determine whether a person is overweight or underweight for his or her height. A
person’s BMI is calculated as follows:
- BMI = weight * 703 / height2
where weight is measured in pounds, and height is measured in inches. The program should
display a message indicating whether the person has optimal weight, is underweight, or is
overweight. A person’s weight is considered optimal if his or her BMI is between 18.5 and 25. If
Qatar University
Fall 2019 CENG106: Computer Programming

the BMI is less than 18.5, the person is considered underweight. If the BMI value is greater than
25, the person is considered overweight.

Q4: Geometry Calculator


Write a program that display’s the following menu:
Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4)

If the user enters 1, the program should ask for the radius of the curcle and then display its
area. Use the formula: area=πr2
If the user enters 2, the program should ask for the length and width of the rectangle and then
display the rectangle’s area. Use the formula: area = length* width
If the user enters 3, the program should as the user for the length of the tringle’s base and its
height, and then display its area. Use the following formula: area=base*height*0.5
If user enters 4, program should end.
Input validation: display error message if the user enters a number outside the range of 1 to 4
when selecting an item from the menu. Do not accept negative values for the circle radius, the
rectangle length and width or the triangle base and height.

Das könnte Ihnen auch gefallen