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.
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.
&& — AND)Problem Statement
Write a C++ program to determine whether a person is eligible to drive. A person must be at least 18 years old and have a valid driving licence.
&&) in an if-else statement.Allowed to drive if both conditions are true; otherwise, display Not allowed to drive.|| — OR)Problem Statement
Write a C++ program to determine whether a student is allowed to enter an examination hall. A student may enter if they have a valid admit card or special permission from the examination authorities.
||) in an if-else statement.Entry allowed if at least one condition is true; otherwise, display Entry denied.&& — AND)Problem Statement
Write a C++ program to determine whether a customer qualifies for free delivery. Free delivery is available only when the order amount is Rs. 3,000 or more and the customer’s address is within the delivery area.
&&) in an if-else statement.Free delivery if both conditions are true; otherwise, display Delivery charges apply.! — NOT)Problem Statement
Write a C++ program to determine whether a student’s library account is active or blocked. Use a Boolean variable named isBlocked to indicate whether the student’s account has been blocked.
isBlocked.true if the account is blocked and false if the account is not blocked.!) in an if-else statement to check the account status.Account active if the account is not blocked; otherwise, display Account blocked.true and false values.&& and || — Mixed Operators)Problem Statement
Write a C++ program to determine whether a student is eligible for university admission. The student must score at least 60 marks and must have either a valid entry test result or an approved entry test exemption.
&&) and OR (||) operators together in an if-else statement.Eligible for admission if the student scores at least 60 marks and either has a valid entry test result or an approved exemption.Not eligible.switch StatementswitchWrite a C++ program that asks the user to enter a day number from 1 to 7. Use a switch statement to determine whether the entered day is a Weekday or a Weekend.
Weekday.Weekend.Invalid day number.Example Output 1:
Enter day number (1-7): 3
Weekday
Example Output 2:
Enter day number (1-7): 7
Weekend
Example Output 3:
Enter day number (1-7): 9
Invalid day number
switchWrite a C++ program that asks the user to enter two numbers of type double and an arithmetic operator (+, -, *, /, or %). Use a switch statement to perform the selected arithmetic operation and display the result.
+, add the two numbers.-, subtract the second number from the first.*, multiply the two numbers./, divide the first number by the second. If the second number is zero, display Cannot divide by zero.%, convert both numbers to integers and calculate the remainder. If the converted second number is zero, display Cannot calculate remainder by zero.Invalid operator.Enter first number: 10.5
Enter operator (+, -, *, /, %): +
Enter second number: 5.2
Result = 15.7
Enter first number: 10
Enter operator (+, -, *, /, %): /
Enter second number: 4
Result = 2.5
Enter first number: 10
Enter operator (+, -, *, /, %): /
Enter second number: 0
Cannot divide by zero
Enter first number: 10
Enter operator (+, -, *, /, %): %
Enter second number: 3
Result = 1
Enter first number: 10
Enter operator (+, -, *, /, %): &
Enter second number: 5
Invalid operator
Note: Use double variables for both inputs. The modulus (%) operator works only with integers in C++, so convert the operands to integers for this operation. Any decimal parts will be discarded during conversion.
switchWrite a C++ program that asks the user to enter a single character. Use a switch statement to check whether the entered character is a vowel (a, e, i, o, or u). The program should recognize both lowercase and uppercase vowels.
a, e, i, o, or u, display Vowel.A, E, I, O, or U, display Vowel.Not a vowel.Enter a character: e
Vowel
Enter a character: U
Vowel
Enter a character: b
Not a vowel
Enter a character: 5
Not a vowel
switchWrite a C++ program to display a menu for a simple Student Management System. Ask the user to enter a choice from the menu and use a switch statement to perform the corresponding action.
Display the following menu:
1, display Displaying student profile.2, display Displaying semester result.3, display Displaying fee status.4, display Exiting the program.Invalid choice.--- Student Management System ---
1. Student Profile
2. Semester Result
3. Fee Status
4. Exit
Enter your choice: 1
Displaying student profile.
--- Student Management System ---
1. Student Profile
2. Semester Result
3. Fee Status
4. Exit
Enter your choice: 3
Displaying fee status.
--- Student Management System ---
1. Student Profile
2. Semester Result
3. Fee Status
4. Exit
Enter your choice: 5
Invalid choice.
switchWrite a C++ program that asks the user to enter a letter grade (A, B, C, D, or F). Use a switch statement to display the corresponding performance message.
A, display Excellent Performance.B, display Very Good Performance.C, display Good Performance.D, display You Passed.F, display You Failed.Invalid grade.A and a).E and display Needs Improvement.Enter your grade (A, B, C, D, F): A
Excellent Performance
Enter your grade (A, B, C, D, F): b
Very Good Performance
Enter your grade (A, B, C, D, F): X
Invalid grade
switchWrite a C++ program that asks the user to enter a month number (1–12). Use a switch statement to display the number of days in the corresponding month.
1, display 31 days for January.2, display 28 days for February.3, display 31 days for March.4, display 30 days for April.5, display 31 days for May.6, display 30 days for June.7, display 31 days for July.8, display 31 days for August.9, display 30 days for September.10, display 31 days for October.11, display 30 days for November.12, display 31 days for December.Invalid month number.Note: Assume February has 28 days. Leap years are not considered.
Enter month number (1-12): 2
February has 28 days.
Enter month number (1-12): 4
April has 30 days.
Enter month number (1-12): 15
Invalid month number
switchDifficulty Level: Advanced
Write a C++ program that simulates a simple ATM system. Display a menu that allows the user to check their account balance, deposit money, withdraw money, or exit the program. Use a switch statement to process the user’s selection.
Thank you for using the ATM. and terminate the program.Invalid choice. Please try again.--- ATM Menu ---
1. Balance Inquiry
2. Deposit
3. Withdrawal
4. Exit
Enter your choice: 1
Current Balance: Rs. 10000
Enter your choice: 2
Enter deposit amount: 2000
Deposit successful.
Updated Balance: Rs. 12000
Enter your choice: 3
Enter withdrawal amount: 3000
Withdrawal successful.
Updated Balance: Rs. 9000
Enter your choice: 3
Enter withdrawal amount: 15000
Insufficient balance.
Enter your choice: 4
Thank you for using the ATM.