Practice C++ programming with coding exercises covering variables, data types, operators, input and output, type casting, conditional statements, loops, functions, arrays, and other C++ fundamentals.
const and #defineWrite a C++ program to demonstrate the use of const and #define for defining constant values.
The program should:
PI using #define.DAYS_IN_WEEK using const and assign it the value 7.PI and DAYS_IN_WEEK.radius and assign it the value 5.0.PI and radius.const variable cannot be changed after initialization.Expected Output:
Value of PI using #define: 3.14159
Days in a week using const: 7
Area of circle with radius 5 is: 78.5397
Write a C++ program that:
a = 5 and b = 2.c of type float.float before performing the division.c.c.2.5
Write a C++ program that takes the student’s name, age, and marks as input and displays them using cout.
Write a C++ program that takes the prices of three items from the user, calculates the total, and displays the result.
Write a C++ program that takes the length and width of a rectangle and calculates:
Perimeter = 2 × (Length + Width)
Display the result using cout.
Write a C++ program that takes marks of three subjects, calculates the average, and displays the result.
Write a C++ program that asks the user to enter their age and displays:
Your age is: 20
Write a C++ program that takes two integers from the user and displays their:
Write a C++ program that takes marks of three subjects and displays the total marks.
Write a C++ program that takes the length and width of a rectangle and calculates its area.
Formula:
Area = Length × Width
Write a C++ program that takes the following information from the user:
Then display all the information using cout.
endlWrite a C++ program that displays your:
Use endl to print each item on a separate line.
setwWrite a C++ program to display the following table using setw(10):
Number Cube
2 8
3 27
4 64
5 125
Write a C++ program that uses both endl and setw() to display a simple student information table containing:
Write a C++ program that takes a number as input and checks whether it is positive, negative, or zero. Display the appropriate message based on the entered number.
Hint: Use an if-else-if ladder.
Write a C++ program that takes an integer as input and determines whether it is even or odd. Display an appropriate message based on the result.
Hint: Use the modulus operator (%) to check the remainder when the number is divided by 2.
Write a C++ program that takes a student’s marks as input. If the marks are 50 or above, display “Eligible”; otherwise, display “Not Eligible”.
Hint: Use an if-else statement to check the marks.
Write a C++ program that takes a student’s marks as input and displays the corresponding grade according to the following criteria:
If the entered marks are less than 0 or greater than 100, display “Invalid Marks”.
Hint: Use an if-else-if ladder to check the marks and assign the appropriate grade. First, validate that the marks are between 0 and 100.
Write a C++ program that takes two numbers as input and compares them. Display the larger number. If both numbers are equal, display “Both numbers are equal.”
Hint: Use an if-else-if ladder to compare the two numbers and handle all three possible cases.
Write a C++ program that takes two inputs: a user verification flag and a password verification flag. Display “Login Successful” only if both flags indicate that the username and password are correct. Otherwise, display “Login Failed”.
Hint: Use nested if statements to check the user verification flag first and then the password verification flag.
Write a C++ program that takes a student’s marks and family monthly income as input. The student is eligible for a scholarship only if both of the following conditions are met:
Display “Scholarship Awarded” if the student meets both conditions. Otherwise, display “Not Eligible for Scholarship”.
Hint: Use nested if statements to check the marks first and then the family income.
Course Registration
Write a C++ program that takes three inputs to check whether a student can register:
Display “Registration Allowed” only if all three requirements are satisfied. Otherwise, display “Registration Not Allowed”.
Hint: Use nested if statements with appropriate else branches to check each requirement one by one.