0% found this document useful (0 votes)
12 views

CS131 - Assignment 1 - Fall'24

Health

Uploaded by

ahmed7778258
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

CS131 - Assignment 1 - Fall'24

Health

Uploaded by

ahmed7778258
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 131 Programming-I

Assignment 1
Instructions:
1. Submission deadline 4 Oct 2024.
2. If you copy from others zero will be given.
3. Assignment should be written with neat handwriting on proper A4 papers.
4. Upload the handwritten assignment in the blackboard, and submit the written
Assignment physically.

1. Explain in details about the logical sections of computer.

2. Explain all the symbols used to draw the flowchart. Write an algorithm, and draw
the flowchart to check a given number is prime from a given range of numbers.

3. Write the algorithm and draw the flowchart to convert height in feet to meter,
weight in pounds to kilogram. Then find the BMI and display the following
message depending
BMI values
Less than 18.5 Underweight
Between 18.5 and 24.9 Normal
Between 25 and 29.9 Overweight
Greater than 29.9 Obese

Hint: 1 feet = 0.3048 meter, 1 pound = 0.4536 kilograms


weight
BMI = 2
height

4. Explain about primary data types with their memory size. Write a C++ program to
demonstrate the memory size of the basic datatypes

5. Write a statement (or comment) to accomplish each of the following (assume that
using declarations have been used for cin, cout and endl):
a) Document that a program calculates the power of two integers.
b) Input unsigned int variable x and y with cin in single statement.
c) Declare unsigned int variable i and initialize it to 1.
d) Declare unsigned int variable power and initialize it to 1.
e) Multiply variable power by x and assign the result to power.
f) Preincrement variable i by 1.
g) Determine whether i is less than or equal to y.
h) Output integer variable power with cout and <<.
6. Write C++ statements to accomplish each of the following:
a) In one statement, assign the product of the current value of x and y to z and
postdecrement the value of x.
b) Determine whether the value of the variable count is divisible by 10. If it is,
print "Count is divisible by 10."
c) Postincrement the variable x by 1, then add it to the variable total.
d) Calculate the remainder after q is divided by divisor and assign the result to q.
Write this statement two different ways.

7. Identify and correct the errors in each of the following statements:


a) if ( c < 7 );
cout << "c is less than 7\n";

b) if ( c => 7 )
cout << "c is equal to or greater than 7\n";

c) if ( age >= 65 )
cout << "Age is greater than or equal to 65" << endl;
else;
cout << "Age is less than 65 << endl";

8. Write the code to check whether a given number is positive or negative using
switch and if..else. Explain dangling else problem.

9. Trace and write the output of the following C++ code?


a) int a= 5, b=2;
b = a-b ;
b -= 1;
a = a/b;
cout<<a;

b) Assume ch is ‘u’ to trace the given code


switch (ch)
{
case 'a':
cout<<"Vowel";
break;
case 'e':
cout<<"Vowel";
break;
case 'u':
cout<<"Vowel";
break;
default :
cout<<"Consonant";
}
10. Write a complete C++ program to calculate car insurance premium based on the
driving record of the driver. The program should calculate the insurance premium
using the following criteria:
 If the driver has more than 3 accidents in the past year, add a surcharge of 25%
to the base premium.
 If the driver has two accidents in the past year, add a surcharge of 10% to the
base premium.
 If the driver has only one accident, add a surcharge of 5% to the base
premium.
 If the driver has zero accidents, apply a discount of 10% to the base premium.
Here are the steps to write the program:
1. Prompt the user to enter the number of accidents in the past year.
2. Based on the entered driving record, find the appropriate surcharge or discount
to the base premium.
3. Calculate and display the final insurance premium by adding up the base
premium and any surcharges or discounts.
Your program should include appropriate variable declarations, conditional statements,
and input/output operations to achieve the desired functionality.

Example: Assuming a base premium of 1000 SAR, two accidents in the past year
would pay (1000 + 0.1 * 1000) = 1100 SAR.

You might also like