Wednesday, September 20, 2023

C++ If else Practice Questions



1.Prompt the user for a positive integer 'n' and calculate the sum of all natural numbers from 1 to 'n'.

2.Take an integer input from the user and display its multiplication table from 1 to 10.

3.Prompt the user to enter an integer and check if it's even or odd.

4.Ask the user for a year and determine if it's a leap year or not.

5.Prompt the user for three numbers and find the greatest among them.

6.Prompt the user to enter a number and determine if it's positive, negative, or zero.

7.Ask the user to enter a character and check if it's a vowel or a consonant.

8.Prompt the user for a positive integer and reverse its digits.

9.Create a simple menu-driven calculator that allows the user to perform addition, subtraction, multiplication, and division on two numbers.

10.Ask the user for a string and reverse it.

11.Prompt the user for two strings and check if they are equal.

12.Ask the user for a character and convert it to lowercase if it's an uppercase letter.

13.Take an integer input from the user and determine if it's a prime number.

14.  Create a program that takes a test score as input and uses if and else if statements to determine the corresponding grade (A, B, C, D, or F). Display the grade.

15.Create a simple menu-driven program that asks the user to choose between two options. Use an if statement to perform the selected action.

16.Write a program that asks the user for their age and uses an if statement to determine the ticket price at a movie theater. Tickets cost $10 for adults (age 18-64), $5 for children (age 0-17), and $7 for seniors (age 65+).

17.Implement a basic password checker. Ask the user to enter a password, and use an if statement to check if it meets certain criteria (e.g., length >= 8 characters, contains at least one uppercase letter and one digit).

18. Ask the user to input a character, and use an if statement to check if it's uppercase, lowercase, a digit, or a special character. Display the result.

19.Ask the user to input a month (1-12) and use if statements to determine the number of days in that month. Display the result.

20. Prompt the user to input the coefficients of a quadratic equation (a, b, c) and use if statements to find and display the real roots of the equation (if they exist).

21.Implement a basic voting system. Ask the user for their age and use an if statement to determine if they are eligible to vote in an election (18 years or older). Display the eligibility status.

22.Prompt the user to enter two integers, and use if statements to check if one is divisible by the other. Display the result.

23.Implement a simple traffic light simulator program. Ask the user for a color ("red," "yellow," or "green"), and use if statements to display the appropriate message based on the color.

24.Create a program that asks the user to input their credit score and uses if statements to provide feedback on their creditworthiness (e.g., poor, fair, good, excellent).

25.Prompt the user for their annual income and credit score. Use if statements to determine whether they are eligible for a loan based on income and credit score criteria.

26. Implement a basic user authentication system. Ask the user for a username and password, and use if statements to check if they match predefined values.

27.Student Gradebook

Create a C++ program that manages a gradebook for a class. Allow the user to input student names and their scores for multiple assignments and exams. Calculate each student's final grade using a weighted average (assignments: 40%, exams: 60%). Display the grades and assign letter grades using if-else statements.

28.Library Catalog System

Develop a C++ program for a library catalog system. Allow users to search for books by title, author, or genre. Implement a menu-driven interface using switch-case statements for user interaction and nested if-else statements to handle various search options.


Tuesday, September 19, 2023

C++ Practice Questions Before If/Else

 Here are the C++ Basic Practice question Before If/Else which will help in logic building \



Basic Arithmetic:

1.Write a code in C++ to display your name, roll number, degree and semester on console in

following way. Use “\t” to give tab space between each field

Please give your C++ code for solving the above question in the space below:

*******************************

Name Roll Number Degree Semester

*******************************

2. Write a program that will take two integers as input , adds them and display results.


3.Ask the user for two numbers , Subtract them and display results.

4.Create a program that multiplies two numbers entered by the user and shows the product.

5.Ask the user to enter two numbers,  display the quotient by dividing them.

6.Ask the user to enter two numbers , divide them and display the remainder  .

7.Calculate the square of a number entered by the user.

8.Calculate the cube of a number entered by the user.

9.Write a code in C++ to display following on console:

*

**

***

****

10.Declare three variables (A,B,C) of type int in C++. Take input from console in each

variable. Now write code such that following is displayed on screen:

A         B        C

[A]*2 [B]*2 [C]*2

[A]+3 [B]+2 [C]+2


Conversion and Calculation:

1.Create a program that converts Celsius to Fahrenheit. Prompt the user for a temperature in     Celsius and display it in Fahrenheit.

2.Prompt the user for the length and width of a rectangle and calculate its area.

3.Ask the user for the radius of a circle and calculate its area.

4.Compute the speed of a car given the distance traveled and the time taken. Prompt the           user  for these values.

5.Calculate simple interest using the principal amount, rate of interest, and time period              entered by the user.

6.Find the ASCII value of a character entered by the user.

7.Create a program that calculates the area of a triangle. Prompt the user for the base and height.

8.Calculate the area of a parallelogram given its base and height. Prompt the user for these values.

9.Calculate the area of a trapezoid. Ask the user for the lengths of the two bases and the height.

10.Convert following algebraic equation into C++ arithmetic expression:

V = IR

Where “R”, “I” and “V” is resistance, current and voltage respectively.

Ask user to enter values for ‘I’ and ‘R’ and display the result of this expression. All variables

can be integers only. For example, if x=2, and a=1, the y should be 15.

11.Single room takes 2 liters of paint mixture whereas 2 liters’ paint mixture cost is 1000 rupees.

Write a C++ program that takes as input the number of rooms to be painted and outputs the total cost to paint

these rooms. (Assume that all rooms are of same standard size.)

12.Write a C++ program that displays a table of 06 entries that contains square and cube of numbers. An excerpt from table is shown.

a    a^2     a^3

2     4        8

3     9        27

13.Suppose ‘x’, ‘y’, and ‘z’ are int variables and ‘w’ and‘t’ are double variables. What value is

assigned to each of these variables after the last statement executes?

x = 17;

y = 15;

x = x + y / 4;

z = x % 3 + 4;

w = 17 / 3 + 6.5;

t = x / 4.0 + 15 % 4 - 3.5;

14.Write a program, which takes an integer as a parameter and display the number in a reverse order. For example, if the user enters the value 12345, your program must display 54321 on the console window.

15.Write a C++ code to make the following pattern (as given below). Input (starting character) will be

given by user through console which is to be stored in a char variable. You are required to print next

three characters according to the given pattern.

Starting Char        Output

A                            C F J

B                            D G K

C                             E H L

Hint:(Use Ascii code to make this program i.e. Ascii code of A is 65).

16.Prompt the user to enter their weight (in kilograms) and height (in meters). Calculate and display their Body Mass Index (BMI) using the formula: BMI = Weight / (Height * Height).

17.Prompt the user to enter two numbers and swap their values without using a third variable.

18.Ask the user for three numbers and calculate and display their average.

19.Prompt the user to enter a character and display its ASCII value.

20.Implement variable swapping without using a third variable, using bitwise XOR.

Ishq Murshid Drama

Ishq Murshid Drama