Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Programming Fundamentals (Assignment # 02)

Uploaded by

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

Programming Fundamentals (Assignment # 02)

Uploaded by

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

Assignment No.

02
Total Marks: 10
Semester: Fall 2022 Due Date: December 22, 2022
Programming Fundamentals

NOTE: Submit your assignment to your class representative in hard form well before the deadline. The submitted file must
contain the program source code along with output screenshot.
PRACTICAL

Question # 01: Write a program that takes length as input in feet and inches. The program should then convert the lengths
in centimeters and display it on screen. Assume that the given lengths in feet and inches are integers.

Based on the problem, you need to design an algorithm as follows:

• Get the length in feet and inches.


• Convert the length into total inches.
• Convert total inches into centimeters.
• Output centimeters.

To calculate the equivalent length in centimeters, you need to multiply the total inches by 2.54. Instead of using the value
2.54 directly in the program, you will declare this value as a named constant. Similarly, to find the total inches, you need
to multiply the feet by 12 and add the inches. Instead of using 12 directly in the program, you will also declare this value
as a named constant. Using a named constant makes it easier to modify the program later.

To write the complete length conversion program, follow these steps:

• Begin the program with comments for documentation.


• Include header files if any are used in the program.
• Declare named constants, if any.
• Write the definition of the function main.

Question # 02: Write a C++ program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and
Computer. Calculate percentage and grade according to following:

• Percentage >= 90%: Grade A


• Percentage >= 80%: Grade B
• Percentage >= 70%: Grade C
• Percentage >= 60%: Grade D
• Percentage >= 40%: Grade E
• Percentage < 40%: Grade F

Question # 03: Write a C++ program to input electricity unit charges and calculate total electricity bill according to the
given condition:

• For first 50 units Rs. 0.50/unit


• For next 100 units Rs. 0.75/unit
• For next 100 units Rs. 1.20/unit
• For unit above 250 Rs. 1.50/unit
• An additional surcharge of 20% is added to the bill
Question # 04: Develop a program in C++ that calculate the factorial of a given number. Use for loop to calculate the
factorial and do – while loop to perform the operation as many times as user want.

Question # 05: What will be the output of the following program? (Dry Run the code and create table to illustrate the
steps).

#include <iostream>

#include <string>

using namespace std;

int main() {

string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};

for(int i = 0; i < 4; i++) {

cout << i << ": " << cars[i] << "\n";

return 0;

Question # 06: Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of
the number is equal to the number itself, then the number is called an Armstrong number.

For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )

************************************************
Best of Luck

You might also like