PROGRAM: 1
PRIME NUMBERS
1. Start All programsTurbo c.
2. Check if num is less than or equal to 1. If it is, return false (because numbers less than or equal to
1 are not prime).
3. Loop from i = 2 up to the square root of num. (We only need to check up to the square root for
efficiency).
4. (Inside the loop): Check if num is divisible by i (i.e., if num % i == 0). If it is, return false
(because we've found a divisor other than 1 and itself, so it's not prime).
5. (After the loop): If the loop finishes without finding any divisors, return true (because the number
is prime).
6. Print a message to the console indicating the range of numbers for which we'll find primes (e.g.,
"Prime numbers between X and Y are:").
7. Loop from the starting number to the ending number (inclusive).
8. (Inside the loop): Call the isPrime() function, passing the current number in the loop as an
argument.
9. (Inside the loop): If isPrime() returns true (meaning the number is prime):
o Print the number to the console, followed by a space.
10. Print a newline character to the console to move the cursor to the next line.
11. Return 0 to indicate that the program executed successfully.
PROGRAM: 2
NUMBER TO WORD CONVERTER
1. Start All programsTurbo c.
2. printWord(int n): Prints the English word for a single digit (0-9) using a switch statement.
main():Get a number from the user,Validate: Is it a 3-digit number and was the input valid (a
number)? If not, print an error, clear the error flags on std::cin, discard the bad input, and exit
with an error code.
3. If valid:
o Get the hundreds digit.
o Print the hundreds digit as a word.
o Get the tens digit.
4. Print the tens digit as a word,Get the units digit.
5. Print the units digit as a word,Print a newline.
6. Save the Program, Compile and Run the Program.
PROGRAM: 3
GEOMETRIC AREA CALCULATOR
1. Start All programsTurbo c.
2. Include the necessary header files: <iostream> for input/output, <cmath> for mathematical
functions (like M_PI), and (potentially) <conio.h> if you're using clrscr() and getch() and are
aware of their portability limitations.
3. Define the Area Class:Create a class named Area.
4. Inside the class, define three overloaded member functions named calculateArea:
o calculateArea(float radius): Takes the radius of a circle as input and returns its area (using
M_PI * radius * radius).
o calculateArea(float length, float width): Takes the length and width of a rectangle as
input and returns its area (using length * width).
o calculateArea(float base, float height): Takes the base and height of a triangle as input
and returns its area (using 0.5 * base * height).
5. Declare variables:
o Create an object of the Area class (e.g., Area area;).
o Declare float variables to store the radius, length, width, base, and height.
6. Get Circle Information and Calculate Area:Prompt the user to enter the radius of a circle,Read
the radius from the user's input and store it in the radius variable,Call the calculateArea(radius)
function of the Area object to calculate the circle's area.
7. Get Rectangle Information and Calculate Area:
Prompt the user to enter the length and width of a rectangle.
Read the length and width from the user's input and store them in the length and width variables.
Call the calculateArea(length, width) function of the Area object to calculate the rectangle's area.
8. Get Triangle Information and Calculate Area:Prompt the user to enter the base and height of a
triangle,Read the base and height from the user's input and store them in the base and height
variables,Call the calculateArea(base, height) function of the Area object to calculate the
triangle's area.
9. Save the Program, Compile and Run the Program.
PROGRAM: 4
INLINE ARITHMETIC FUNCTIONS
10. Start All programsTurbo c.
11. Declare integer variables num1 and num2 to store two integers, float variables num3 and
num4 to store two floating-point numbers.
12. Prompt the user to input two integers (num1 and num2) and read the input values into the
variables num1 and num2.
13. Perform and Display Arithmetic Operations on Integers like Addition, Subtraction and
Multiplication by using their function
14. Input Two Floating-Point Numbers (num3 and num4) then Read the input values into the
variables num3 and num4.
15.
16. Perform and Display Division Call the divide () function with num3 and num4 as
arguments. The divide () function performs the division of num3 by [Link] the
divide() function:
Check if num4 is zero to avoid division by zero.
If num4 is not zero, return the result of the division and display it.
If num4 is zero, display an error message: "Error! Division by
zero." and return zero.
17. Save the Program, Compile and Run the Program.
PROGRAM: 5
STUDENT MARK LIST GENERATOR
1. start->all program->turbo c
2. Define a Student class with attributes name, rollNumber, and marks.
3. Create member functions getDetails() to input and displayDetails() to output details.
4. In main(), declare an array of Student objects (students[50]).
5. Prompt user for the number of students (n) and read input.
6. Use a loop to call getDetails() for each student object to input data.
7. Use another loop to call displayDetails() for each student object to display data.
8. End the program using getch() or equivalent pause functionality.
9. Save the program ,compile and run the program.
PROGRAM: 6
CONSTRUCTOR OVERLOADING
1. start->all program->turbo c
2. Declare float variables for length, width, and height in the Box class.
3. Create four constructors: default (sets all dimensions to 1), one with length, one with length and
width, and one with all three dimensions.
4. Define a displayVolume() function that calculates and displays the box volume.
5. In main(), create four Box objects using different constructors.
6. Display the volume for each Box object using the displayVolume() method.
7. Save the program ,compile and run the program.
PROGRAM: 7
OVERLOADING UNARY-OPERATOR
1. start->all program->turbo c
2. Define a Counter: Create a class to represent a counter, holding a number.
3. Initialize: Give the counter a starting value.
4. Increment: Define how to increase the counter's value by one.
5. Show Value: Define how to display the counter's current value.
6. Create Counter: In your main program, make a counter object, starting at 5.
7. Show Initial Value: Display the counter's initial value (5).
8. Increment and Show: Increase the counter by one, then display its new value (6).
9. Save the program ,compile and run the program.
PROGRAM: 8
MULTIPLE INHERITANCE
1. start->all program->turbo c
2. Declare a std::string named name to store the person's name,Declare an integer age to store the
person's age.
3. Define getPersonDetails():
a. Prompt the user to enter the name.
b. Read the name using std::getline() (to handle names with spaces).
c. Prompt the user to enter the age.
d. Read the age.
4. Define displayPersonDetails() (marked const):
a. Print "Name: " followed by the person's name.
b. Print "Age: " followed by the person's age.
5. Declare an integer employeeID to store the employee's ID and Declare a float salary to store the
employee's salary.
6. Define getEmployeeDetails():
a. Prompt the user to enter the employee ID.
b. Read the employee ID.
c. Prompt the user to enter the salary.
d. Read the salary.
7. Define displayEmployeeDetails() (marked const):
a. Print "Employee ID: " followed by the employee ID.
b. Print "Salary: " followed by the salary.
8. Declare a std::string named department to store the manager's department.
9. Define getManagerDetails():
a. Call Person::getPersonDetails() to get the person's details. (Crucial for disambiguation)
b. Call Employee::getEmployeeDetails() to get the employee's details. (Crucial for
disambiguation)
c. Prompt the user to enter the department.
d. Read the department using std::getline().
10. Define displayManagerDetails() (marked const):
a. Call Person::displayPersonDetails() to display the person's details. (Crucial for
disambiguation)
b. Call Employee::displayEmployeeDetails() to display the employee's details. (Crucial for
disambiguation)
c. Print "Department: " followed by the manager's department.
11. Create a Manager object named m,Print "Enter manager details:" and Call [Link]()
to get all the manager's information.
12. Call [Link]() to display all the manager's information.
13. Return 0 (indicating successful execution). Save the program ,compile and run the program.
PROGRAM: 9
MULTI LEVEL INHERITANCE
1. start->all program->turbo c
2. Define a function start() that prints "Vehicle started." to the console.
3. Define a function drive() that prints "Car is being driven." to the console. Car also implicitly has
the start() function from Vehicle.
4. Define a function boost() that prints "SportsCar boost activated!" to the console. SportsCar
implicitly has the start() function from Vehicle and the drive() function from Car.
5. Create an object of the SportsCar class (e.g., mySportsCar).
6. Call [Link](): This calls the start() function inherited from the Vehicle class.
7. Call [Link](): This calls the drive() function inherited from the Car class.
8. Call [Link](): This calls the boost() function defined in the SportsCar class.
9. Return 0 to indicate successful program execution.
PROGRAM: 10
HIERARCHICAL INHERITANCE
1. start->all program->turbo c
2. Declare name (string) and age (int) as members and also Define getDetails() (virtual):
a. Prompt for and read name.
b. Prompt for and read age.
3. Define displayDetails() (virtual and const):
a. Print name and age.
4. Declare course (string) as a member and then Override getDetails():
a. Call Person::getDetails() to get name and age.
b. Prompt for and read course.
5. Override displayDetails() (const):
a. Call Person::displayDetails() to display name and age.
b. Print course.
6. Define Faculty Class (Derived from Person):
Declare department (string) as a member.
Override getDetails():
o Call Person::getDetails() to get name and age. (Important!)
o Prompt for and read department.
Override displayDetails() (const):
o Call Person::displayDetails() to display name and age. (Important!)
o Print department.
7. In main() Function:Create a Student object (student),Create a Faculty object (faculty),Prompt
for and get student details ([Link]()),Prompt for and get faculty details
([Link]()),Display student details ([Link]()),Display faculty details
([Link]()).
8. Return 0 to indicate successful program execution.
PROGRAM: 11
VIRTUAL FUNCTION
1. Start -> all programs-> turbo c.
2. Include Headers: #include <iostream.h> and #include <conio.h>.
3. Define Base Class Shape: Declare a virtual function area().
4. Define Derived Class Circle: Inherit Shape, add radius, and override area().
5. Define Derived Class Rectangle: Inherit Shape, add length & width, and override area().
6. Define main() Function: Use clrscr(); (optional in modern C++).
7. Shape *shapePtr: Create a base class pointer.
8. Circle Object c(5.0): Initialize with radius 5.0.
9. Rectangle Object r(4.0, 6.0): Initialize with length 4.0 and width 6.0.
10. Assign shapePtr = &c: Point to Circle object,Call shapePtr->area(): Executes Circle's
overridden area(),Assign shapePtr = &r: Point to Rectangle object.
11. Call shapePtr->area(): Executes Rectangle's overridden area(),Use getch();: Wait for user
input (optional in modern C++
12. save the program, run the program.
PROGRAM: 12
BINARY FILE MARK LIST
1. Start -> all program -> turbo c
2. Include necessary headers (#include <iostream.h>, #include <conio.h>, #include <fstream.h>).
3. Define Student class with name, rollNumber, and marks as private members.
4. Implement getDetails() to take input for student details.
5. Implement displayDetails() to print student details
6. Define writeToFile() to get student details and write them to [Link].
7. Define readFromFile() to read student records from [Link] and display them.
8. Define main() function to display a menu for adding or displaying records.
9. Use a do-while loop to handle user input and call appropriate functions.
10. Use switch-case to execute writeToFile(), readFromFile(), or exit based on user choice.
11. End program execution using getch() after user exits the menu.
12. Save the program,compile and run the program.
PROGRAM: 13
COUNTING OBJECTS IN FILE
1. Start ->all program->turbo c
2. Define a Product class with variables for name, ID, and price, and member functions for input
(getDetails) and output (displayDetails) operations.
3. Create the addProduct function to write product details to the binary file [Link] in append
mode.
4. Create the countProducts function to open [Link] in binary mode, read the file, and count
the number of product records.
5. In main, initialize variables for user choice and display a menu with options to add a product,
count products, or exit.
6. Use a do-while loop to repeatedly display the menu until the user selects the exit option.
7. In the loop, execute the addProduct function for adding products or the countProducts function
for counting products based on user input.
8. Handle invalid menu choices by displaying an error message and re-prompting the user.
9. End the program when the exit option is selected.
10. Save the program, compile and run the program.
RESULT: The Above Program Was Verified and Executed
Successfully.(for all the programs)