Sei sulla pagina 1di 6

Programming Fundamentals

Assignment # 02
Please read the following instructions carefully before submitting the assignment.

It should be clear that your assignment will not get any credit if the assignment is copied (partial or full)
from any source (websites, forums, students etc.). Moreover, no assignment will be accepted after due
date.

Assignment Submission

Deadline: 24 Oct, 2019


Submission Format: Printed Form (Codes with snapshot of the output of every program)

Questions

1. Write a program in C++ to find Size of fundamental data types.


Sample Output:
Find Size of fundamental data types :
------------------------------------------
The sizeof(char) is : 1 bytes
The sizeof(short) is : 2 bytes
The sizeof(int) is : 4 bytes
The sizeof(long) is : 8 bytes
The sizeof(long long) is : 8 bytes
The sizeof(float) is : 4 bytes
The sizeof(double) is : 8 bytes
The sizeof(long double) is : 16 bytes
The sizeof(bool) is : 1 bytes

2. Write a program in C++ to swap two numbers.


Sample Output:
Swap two numbers :
-----------------------
Input 1st number : 25
Input 2nd number : 39
After swapping the 1st number is : 39
After swapping the 2nd number is : 25

3. Write a program in C++ to calculate the volume of a sphere.


Sample Output:
Calculate the volume of a sphere :
---------------------------------------
Input the radius of a sphere : 6
The volume of a sphere is : 904.32

4. Write a program in C++ to find the Area and Perimeter of a Rectangle.


Sample Output:
Find the Area and Perimeter of a Rectangle :
-------------------------------------------------
Input the length of the rectangle : 10
Input the width of the rectangle : 15
The area of the rectangle is : 150
The perimeter of the rectangle is : 50

5. Write a program in C++ to find the area and circumference of a circle.


Sample Output:
Find the area and circumference of any circle :
----------------------------------------------------
Input the radius(1/2 of diameter) of a circle : 5
The area of the circle is : 78.5397
The circumference of the circle is : 31.4159

6. Write a program in C++ to convert temperature in Celsius to Fahrenheit.


Sample Output:
Convert temperature in Celsius to Fahrenheit :
---------------------------------------------------
Input the temperature in Celsius : 35
The temperature in Celsius : 35
The temperature in Fahrenheit : 95

7. Write a program in C++ to convert temperature in Fahrenheit to Celsius.


Sample Output:
Convert temperature in Fahrenheit to Celsius :
---------------------------------------------------
Input the temperature in Fahrenheit : 95
The temperature in Fahrenheit : 95
The temperature in Celsius : 35

8. Write a program in C++ that converts kilometers per hour to miles per hour.
Sample Output:
Convert kilometers per hour to miles per hour :
----------------------------------------------------
Input the distance in kilometer : 25
The 25 Km./hr. means 15.5343 Miles/hr.

9. Write a program in C++ to compute quotient and remainder.


Sample Output:
Compute quotient and remainder :
-------------------------------------
Input the dividend : 25
Input the divisor : 3
The quotient of the division is : 8
The remainder of the division is : 1

10. Write a C++ program to display the current date and time.
Sample Output:
Display the Current Date and Time :
----------------------------------------
seconds = 57
minutes = 33
hours = 12
day of month = 6
month of year = 7
year = 2017
weekday = 4
day of year = 186
daylight savings = 0
Current Date: 6/7/2017
Current Time: 12:33:57

11. Write a program in C++ to print the area of a polygon.


Sample Output:
Print the area of a polygon:
---------------------------------
Input the number of sides of the polygon: 7
Input the length of each side of the polygon: 6
The area of the polygon is: 130.821

12. Write a program that inputs the distance traveled and speed of vehicle. It calculates the time
taken to reach its destination and print it.
Sample Output:
Enter the distance traveled (in km): 100
Enter the speed of vehicle (kmh): 10
Time taken to reach its destination: 10 hours

13. Write a program that takes a 3-digit number from user and display the reverse of that number.
For example if user enters 123, then the program should display 321.

14. Write a program that will prompt the user to enter number of hours. Your program should display
the number of weeks, days and hours within the input number of hours.
Sample Output:
Enter number of hours: 200
Weeks: 1
Days: 1
Hours: 8

15. Write a program in C++ to check whether a number is positive, negative or zero.
Sample Output:
Check whether a number is positive, negative or zero :
-----------------------------------------------------------
Input a number : 8
The entered number is positive.

16. Write a program that inputs two numbers from user and find if second number is square of first
number.
Sample Output:
Enter first number: 5
Enter second number: 25
Second number is square of first number

17. Write a program that inputs the total and obtained marks of matric result. The program should
also input the total and obtained marks of intermediate (Part 1). Then it should display the merit
of a student who wants to take admission in UOG.
(Note: Admission Criteria is 30% matric result and 70% inter result.)
Sample Output:
Enter total marks of matric: 1100
Enter obtained marks of matric: 900
Enter total marks of intermediate (part 1): 510
Enter obtained marks of intermediate (part 1): 400
Your merit is 79.44%

18. Write a program that takes 3 numbers from user and find maximum from these numbers.

19. Write a program that takes a number from user and find whether it is even or odd.

20. Write a program that takes a year from user and find whether it is a leap year or not.
(Note: Any year Dividable by 4 is a leap year. E.g. 2004, 2008, 1996 etc.)

21. Write a program that inputs salary and grade. It adds 50% bonus if the grade is greater than 15.
It adds 25% bonus if the grade is 15 or less and then display the total salary.
Sample Output:
Enter Grade: 17
Enter Basic Salary: 16000
Your Total Salary is: 24000

22. Write a program to calculate your total marks of a single course out of 100 in University.
Weightage of assessments is as follows:
Assignments: 10%
Quizzes: 5%
Project: 10%
Mid-Term Exam: 25%
Final-Term Exam: 50%
You have 4 assignments and 4 quizzes for one course. For each assignment, if total marks are 10,
then it means have to take 10% of the obtained marks out of 4 assignments whose total marks
are 40. Same is the case of quiz, you need to take 5% of the obtained marks out of 4 quizzes
whose total marks are 40. There will be single project, mid exam and final exam. You are required
to calculate and display the obtained marks out of 100 in single course.
Sample Output:
Enter obtained marks of assignment 1: 10
Enter obtained marks of assignment 2: 8
Enter obtained marks of assignment 3: 7
Enter obtained marks of assignment 4: 9

Enter obtained marks of quiz 1: 5


Enter obtained marks of quiz 2: 6.5
Enter obtained marks of quiz 3: 10
Enter obtained marks of quiz 4: 7
Enter obtained marks of Project: 8
Enter obtained marks of Mid-Term Exam: 20
Enter obtained marks of Final-Term Exam: 40

Your Total marks out of 100 are: 80.2

Potrebbero piacerti anche