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

HELLO

The document contains 35 programming problems related to C++ concepts like conditional statements, loops, functions, arrays, matrices. The problems cover a wide range of concepts including displaying tabular data, calculating area and volumes, decision making using if-else and switch statements, arithmetic and geometric series calculations using loops, finding maximum, minimum, sum and average of data, etc. The student is expected to write C++ code to solve each problem and display the output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
231 views

HELLO

The document contains 35 programming problems related to C++ concepts like conditional statements, loops, functions, arrays, matrices. The problems cover a wide range of concepts including displaying tabular data, calculating area and volumes, decision making using if-else and switch statements, arithmetic and geometric series calculations using loops, finding maximum, minimum, sum and average of data, etc. The student is expected to write C++ code to solve each problem and display the output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CS-102 Problem Set:

1. Write a C++ program to display the following verse: [Hint: use of cout statement].

PART NO. PRICE


T1267 $6.34
T1300 $8.92
T2401 $65.40
T4482 $36.99
2. Write a program to enter length in centimeter and convert into meter and kilometer [Hint:
1meter=100cm; 1km=100000cm; meter=cm/100; km=cm/100000].

3. Write an interactive program that contains an if statement that may be used to compute the area
of a square (𝑎𝑟𝑒𝑎 = 𝑠𝑖𝑑𝑒 2 ) or a circle ( 𝑎𝑟𝑒𝑎 = 𝜋 ∗ 𝑟𝑎𝑑𝑖𝑢𝑠 2 ) after prompting the user to
type the first character of the figure name (S or C).

4. Implement the following decision table using a nested if statement. Assume that the grade point
average is within the range 0.0 through 4.0.

5. Write a multiple-alternative if statement to display a message indicating the educational level


of a student based on the student’s number of years of schooling (0, none; 1–5, elementary
school; 6–8, middle school; 9–12, high school; more than 12, college). Print a message to
indicate bad data as well.

6. Implement the following decision table using a multiple-alternative if statement. Assume that
the wind speed is given as an integer.

7. Write a multiple-alternative if statement to implement the following decision table that


categorizes a systolic blood pressure reading (pressure as ventricles contract) as “normal,”
“pre-hypertension,” or “hypertension.” Assume that the systolic blood pressure has been input
as an integer.

8. Write a switch statement that assigns to the variable lumens the expected brightness of a
standard light bulb whose wattage has been stored in watts. Use the below table. Assign −1 to
lumens if the value of watts is not in the table.

9. Write a program that calculates the user’s body mass index (BMI) and categorizes it as
underweight, normal, overweight, or obese, based on the following table from the United States
Centers for Disease Control:

To calculate BMI based on weight in pounds ( wt_lb ) and height in inches ( ht_in ), use the
below formula (rounded to tenths). Further prompt the user to enter weight in pounds and
height in inches.

10. A hotel has a pricing policy as follows:


2 people: $85
3 people: $90
4 people: $95
Additional people: $6 per person
If the customer is staying on company business, there is a 20% discount. If the customer is
over 60 years of age, there is a 15% discount. A customer does not receive both discounts.
Given the above data, print the cost of the room.

11. An acute angle is less than 90 degrees, an obtuse angle is greater than 90 degrees, and a right
angle is equal to 90 degrees. Using this information, write a C++ program that accepts an angle,
in degrees, and displays the type of angle corresponding to the degrees entered.

12. The quadrant in which a line starting from the origin is located is determined by the angle the
line makes with the positive x axis, as follows:

Using this information, write, compile, and run a C++ program that accepts the angle of the
line as user input and determines and displays the correct quadrant for the input data. (Note: If
the angle is exactly 0, 90, 180, or 270 degrees, the corresponding line doesn’t reside in any
quadrant but lies on an axis.)

13. Each storage drive in a shipment is stamped with a code from 1 to 4, indicating the following
storage capacities:

Write, compile, and run a C++ program that accepts the code number as an input value and,
based on the value entered, displays the correct storage drive capacity. [Hint: use switch
statement].

14. Write a switch statement to select an operation based on the value of inventory. Increment
total_paper by paper_order if inventory is 'B' or 'C' ; increment total_ribbon by ribbon_order
if inventory is 'E' , 'F' , or 'D' ; increment total_label by label_order if inventory is 'A' or 'X' .
Do nothing if inventory is 'M' . Display an error message if the value of inventory is not one
of these eight letters.

15. The National Earthquake Information Center has asked you to write a program implementing
the following decision table to characterize an earthquake based on its Richter scale number.
16. Write a program that interacts with the user like this:

(1) Carbon monoxide


(2) Hydrocarbons
(3) Nitrogen oxides
(4) Nonmethane hydrocarbons
Enter pollutant number>> 2
Enter number of grams emitted per mile>> 0.35
Enter odometer reading>> 40112
Emissions exceed permitted level of 0.31 grams/mile.

Use the table of emissions limits below to determine the appropriate message.

17. An arithmetic series is defined by the following:


a + (a + d ) + (a + 2d ) + (a + 3d ) + ˙˙˙ + [(a + (n - 1)d )]
a is the first term.
d is the “common difference.”
n is the number of terms to be added.
Using this information, write a C++ program that uses a while loop to display each term and
determine the sum of the arithmetic series having a = 1, d = 3, and n = 100. Make sure your
program displays the value it has calculated.

18. A geometric series is defined by the following:


𝒂 + 𝒂𝒓 + 𝒂𝒓𝟐 + 𝒂𝒓𝟑 + ˙˙˙ + 𝒂𝒓𝒏−𝟏
a is the first term.
r is the “common ratio.”
n is the number of terms in the series.
Using this information, write a C++ program that uses a while loop to display each term and
determine the sum of a geometric series having a = 1, r = .5, and n = 10. Make sure your
program displays the value it has calculated.
19. Write a C++ program to produce a table of the numbers 0 through 20 in increments of 2, with
their squares and cubes.

20. Four experiments are performed, and each experiment has six test results. The results for each
experiment are given in the following list. Write, compile, and run a C++ program using a
nested loop to compute and display the average of the test results for each experiment.

21. Write, compile, and run a C++ program that continuously requests a grade to be entered. If the
grade is less than 0 or greater than 100, your program should print a message informing the
user that an invalid grade has been entered; else, the grade should be added to a total. When a
grade of 999 is entered, the program should exit the repetition loop and compute and display
the average of the valid grades entered.

22. Write a C++ program that takes a number from user and calculates its factorial. The program
repeatedly asks user for a number and calculates its factorial until user enters a zero number.

23. Write a C++ program that input the pairs of integers from user until it reaches a pair in which
the first integer evenly divides the second.

24. Using nested for loops print the following outputs:


25. Write a function named findAbs() that accepts a double-precision number passed to it,
computes its absolute value, and displays the absolute value. A number’s absolute value is the
number itself if the number is positive and the negative of the number if the number is negative.

26. The volume, V, of a sphere is given by this formula, where r is the sphere’s radius:

Using this formula, write, compile, and run a C++ function named spherevol() that accepts a
sphere’s radius and then calculates and displays its volume.

27. Write a program that inputs two numbers and arithmetic operator from user. Make sure to
allow the user to input the operator from these: +, -, *, / or %. Further based on the arithmetic
operator an operation between two numbers is performed and result will be displayed.

28. Write a function to calculate the factorial value of an integer passed as an argument. Call this
function from main( ) and print the results in main( ).

29. Write a function that receives two numbers as an argument and display all prime numbers
between these two numbers. Call this function from main( ).

30. Write a C++ program that inputs ten integer type values from user and display their sum and
average.

31. Write a C++ program that inputs ten integer type values from user and display the minimum
and maximum values among them.

32. Write a C++ program that input the names of five students from user, store them in a 2D array
and then display all those names.

33. Write, compile, and run a C++ program that creates an array of five integer numbers and
displays these numbers in reverse order.

34. Write, compile, and run a C++ program that specifies three one-dimensional arrays named
price, amount, and total. Each array should be capable of holding 10 elements. Using a for
loop, input values for the price and amount arrays. The entries in the total array should be the
product of the corresponding values in the price and amount arrays (so
total[i]ƒ=ƒprice[i]ƒ*ƒamount[i]). After all the data has been entered, display the following
output, with the corresponding value under each column heading:
Total price amount
----- ----- ------

35. Write a C++ program that displays the values on the diagonal of 3*4 matrix, sum of the
diagonal entries and average of diagonal entries of 3*4 matrix.

You might also like