CS131 - Assignment 1 - Fall'24
CS131 - Assignment 1 - Fall'24
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.
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
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.
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.
Example: Assuming a base premium of 1000 SAR, two accidents in the past year
would pay (1000 + 0.1 * 1000) = 1100 SAR.