Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

<<Your Name>>

<<Enrollment No.>>

Week 1
28-08-2023 (B-Section)
29-08-2023 (A-Section)
Simple C++ Programs

Aim

Use the following concepts from C++ to solve the given programming problems.

 Input/Output (I/O): Understanding how to read input from the user (using cin) and display
output (using cout).
 Variables: Declaring and using variables to store data, such as integers, strings, and characters.
 Data Types: Knowing the different data types in C++ (int, double, char, string, etc.) and how
to use them.
 Operators: Using operators like +, -, *, / for basic arithmetic calculations, logical operators,
etc.
 Control Flow: Understanding the flow of a program's execution based on conditions and
loops.
o Conditional Statements: Using if, else if, and else statements to make decisions based
on conditions.
o Loops: Using for, while, and do-while loops for repetitive tasks.
 Comments: Adding appropriate comments to your code to make it more readable and explain
its functionality.

Problem Statements

1. Write a program that takes the marks of a student for various courses (at least 4 theory & 2
lab) along with corresponding number of credits & grade points. Compute the SGPA and print
the final grade sheet as per the following criteria, with institute header, student details, course
details.
Marks obtained Grade point Grade
91-100 10 A+
81-90 9 A
71-80 8 B+
61-70 7 B
51-60 6 C+
40-50 5 C
< 40 0 F
2. Take n as input from the user and write a program that works as follows.
 If n is odd, evaluate and print the factorial value of n.
 If n is even, evaluate and print the sum of digits present in n.
Sample input & output:
Input: n = 5
Output: factorial(5) = 120

3. Build a simple calculator that performs basic arithmetic operations (*, /, +, -, %) upon 2
integers entered by the user. Repeat prompting the user to enter inputs until user wants to
explicitly exit from the calculator application.
Sample input & output:
Input: n1 = 5 n2 = 10 operator: +
Output: 15

1
<<Your Name>>
<<Enrollment No.>>

4. Develop a number guessing game where your C++ program remembers a secret number and
the user needs to guess the secret number. Keep prompting user until the user finds the secret
number or user exhausted with guess limit. Provide hints like "too high" or "too low" after
each guess until they guess the correct number.

5. Design a simple ATM machine program that allows users to check their balance, withdraw
money, and deposit money. Use appropriate conditionals and loops for different operations.

6. Given a positive integer, write a program that checks whether a given number is a palindrome
or not. For instance, the number 12321 is a palindrome number, but 1451 is not a palindrome
number. A number palindrome is a number that remains the same when its digits are
reversed. In other words, if you read the number from left to right and from right to left, you
will get the same number. Negative numbers are not palindromic.

7. Given a number N, verify if N is prime or not. Return true if N is prime, else return false.
Sample input & output:
Input: 7
Output: True

8. Given two integers dividend and divisor, divide two integers without using multiplication (*),
division (/), and mod (%) operator. The integer division should truncate toward zero, which
means losing its fractional part. For instance, 8.345 could be truncated to 8, and -2.7335 could
be truncated to -2. Write a program to return the quotient after dividing dividend by divisor.
Sample input & output:
Input: dividend = 10, divisor = 3
Output: 3
Explanation: 10/3 = 3.33333... which is truncated to 3.

9. Given an integer N. The task is to determine if N is a Happy Number. A Happy number is a


number defined by the following process:
 Start with any positive integer, and replace the number with the sum of the squares
of its digits.
 Repeat the process until the number equals 1, or it loops endlessly in a cycle which
does not include 1.
 Those numbers for which this process ends in 1 are happy numbers.
Sample input & output:
N=7
Squaring, N = 49. Now, N = 42 + 92 = 97.
N = 92 + 72 = 130
N = 12 + 32 + 02 = 10
N = 10 + 02 = 1
Output: True

10. Consider the scenario where the kitchen staff prepares all of its pancakes for the day and
arranges them into two stacks. Initially, the stack on the left has L pancakes, and the stack on
the right has R pancakes.
This restaurant’s customers behave very consistently: the ith customer to arrive (counting
starting from 1) always orders i pancakes. When the ith customer places their order of i

2
<<Your Name>>
<<Enrollment No.>>

pancakes, you take i pancakes from the stack that has the most pancakes remaining (or from
the left stack if both have the same amount). If neither stack has at least i pancakes, the
restaurant closes and the ith customer does not get served any pancakes. You never complete
an order using pancakes from both stacks.
Given the initial numbers of pancakes in each stack L and R, write a program to know how
many customers will be served, and how many pancakes will remain in each stack when the
restaurant closes.
Sample input & output:
Input: L = 8 R = 11
Output: 5 0 4

You might also like