You are on page 1of 74

NAME: ASWIN

ROLL NO: CH.EN.U4CSE22102

PROGRAM ON CHARACTER,DATA TYPE,ARRAY,STRUCT,CLASS

Aim:

Write a C++ program that accepts a character and print the ASCII value of the same character as output.

Algorithm:

❖ Declare a character variable a.


❖ Prompt the user to enter a character and read the input into a.
❖ Display the character entered by the user and its corresponding ASCII value
❖ End the program.

Code:

Output:

Result:

Thus a program in C++ to find the ASCII value of the character has been studies and executed successfully.

PROGRAM-2

Aim:

Write a C++ program to declare char, short, int, unsigned int, unsigned long, float, double, long double
datatype variables and then print the storage space reserved for those variables. (Various built-in data types).

Algorithm:

❖ Start the program.


❖ Declare variables for the datatypes.
❖ Use the sizeof operator to find the size of each variable in bytes and store the result in separate variables.
❖ Print the size of each datatype.
❖ End the program.
Code:

Output:

Result:

Thus a program in C++ to find the storage space for the datatypes has been studied and executed
successfully.

Program:3

Aim:

To write a C++ program that inputs five numbers and calculate the sum and average of entered number using
float array.

Algorithm:

❖ Start the program.


❖ Prompt the user to enter the size of the array.
❖ Take input for each number in a loop, summing them up in a variable sum.
❖ Calculate the average by dividing the sum by n.
❖ Display the elements in an array the sum and the average.
❖ End the program.
Code:

Output:

Result:

Thus the program in C++ to calculate the sum and average of the numbers has been studied and executed
successfully.
PROGRAM-4

AIM:

Declare a struct storing the following information related to students: student_name, roll_num, marks. Create a
struct object and store the values of the object by taking input from the user. Add a function that displays the
struct object values. (struct, function)

ALGORITHM:

❖ Start the program


❖ Declare a struct student with three data members: student_name,roll_num and marks.
❖ Take input for each data member of the student struct object.
❖ Display the students information
❖ End the program.

code:

Output:

RESULT:
Thus a program in C++ to input the students name ,roll no and marks has been studied and executed
successfully.
PROGRAM-5
AIM:
Write a C++ program create the student class with the following data members: student_name, roll_num,
marks1, marks2. Take name, roll number, marks1 and marks2 information from user. Calculate the mean
value of marks and display student_name, roll_num, mean mark values.
ALGORITHM:
❖ Start the program.
❖ Create a class called "student."
❖ Declare the private data members: student name (string), roll num (integer), marks1 (integer), and marks2
(integer).
❖ Define the public member functions "get" and "put" to handle input and output operations.
❖ Inside the "get" function, display a prompt to enter the student's details.
❖ Accept input for student name, roll num, marks1, and marks2 from the user using cin.
❖ Inside the "put" function and calculate the mean of marks (mean = (marks1 + marks2) / 2).
❖ Display the student's name, roll number, and mean marks on the console using cout.
❖ Create an object "s" of the "student" class.
❖ Call the "get" function on the "s" object to get the student's details from the user.
❖ Call the "put" function on the "s" object to display the student's information and mean marks.
❖ End the program.

CODE:

OUTPUT:
RESULT:
Thus a program in C++ to input the details of the student and to find the mean value of the marks has be
studied and executed successfully.
LAB-2
PROGRAM-1
AIM:
To create a class workers mentioning their id, name and department to which the
belong. Compute their weekly wages for the number of hours they work, fixing a
nominal pay rate which is a sensitive data. Include the Accessor and mutator member
functions to set and display the wages.
ALGORITHM:

1. Create a class named "Worker" with private member variables for id,
name,department, nominalPayRate, and weeklyWages.
2. Define a constructor for the "Worker" class that takes workerId,
workerName,workerDept, and payRate as parameters and initializes
the corresponding member variables.
3. Define a public member function "getWeeklyWages()" that returns the
value ofthe "weeklyWages" member variable.
4. Define a public member function "setWeeklyWages(double
hoursWorked)" thattakes the number of hours worked as a parameter.
5. Inside the "setWeeklyWages()" function: a. Calculate the weekly wages
by multiplying the nominal pay rate with the hours worked and store
the result inthe "weeklyWages" member variable.
6. Define a public member function "displayDetails()" that displays the
worker's ID,name, department, and weekly wages.
7. In the "main" function Create a "Worker" object.
8. Run the program.
CODE:
OUTPUT:

RESULT:
The above given program executes correctly and the details of the worker are given asoutput
correctly.
PROGRAM-2
AIM:
Write a C++ program that uses an area () function for the calculation of area of a triangle
or a rectangle or a square. Number of sides ( 3 for a triangle, 2 for a rectangleand 1 for a square)
suggest about the shape for which area is to be calculated. [ Function Overloading ]

ALGORITHM:
1. Include necessary header files

2. Define the functions for calculating areas


3. In the `main` function:
• Declare a variable `side` to store the number of sides.
• Output a prompt to the user asking for the number of sides (3 for triangle, 2
• for rectangle, 1 for square).
• Read the input value for `side` from the user.
• Declare a variable `result` to store the calculated area, initializing it to 0.0.
• Use conditional statements to check the value of `side` , If none of the conditions are
met, output an error message and return with an exit code of 1.
• Output the calculated area stored in the `result` variable.
Return 0 to indicate successful execution of the program
CODE:

OUTPUT:

RESULT:
The above program has executed correctly and output is given correctly of any of the
given 3 shapes
PROGRAM-3
AIM:
To create a class named 'complex' with two data members- real and imag and afunction to
display the value which is in the form of 'a+ib'.
The class has three constructors which are :
1 - having no parameter - values of both real and imag are assigned zero.
2 - having two numbers as
parameters
3 - Copy constructor
4 – Function to add two complex numbers

ALGORITHM:
1. The code defines a class named `Complex` to represent complex numbers with private
member variables `real` and `imag` of type `int`.

2. The `Complex` class has two constructors

3. The class has a member function `display` that outputs the complex number in the format
`real + imagi` with the correct sign for the imaginary part.

4. The class also has a member function `add` that takes a constant reference to another
`Complex` object (`other`) as a parameter. It returns a new `Complex` object representing the
sum of the current complex number and the `other` complex number.

5. In the `main` function:


• Three `Complex` objects (`c1`, `c2`, and `c3`) are created with different
constructorsand values.
• The `display` function is used to output the values of `c1`, `c2`, and `c3`.
• The sum of `c2` and `c3` is calculated using the `add` function and stored in a new
`Complex` object (`sum`).
• The `display` function is used again to output the sum of `c2` and `c3`.

The program then returns 0 to indicate successful execution.


CODE:
OUTPUT:

RESULT:
The above program executes perfectly and the output is shown correctly.
PROGRAM-4
AIM:
To create a class 'Student' with three data members which are name, age and address. The
constructor of the class assigns default values to name as "unknown", age as '0' and address
as "not available". It has two functions with the same name 'setInfo'. First function has two
parameters for name and age and assigns the same whereas the second function takes has
three parameters which are assigned to name, age and address respectively. Print the name,
age and address of 10 students.

ALGORITHM:

1. The code defines a class named `Student` with private member variables `name`, `age`, and
`address`, and public member functions to set and display student information.

2. The `Student` class has a default constructor that initializes the member variables with
defaultvalues: "unknown" for name, 0 for age, and "not available" for address.

3. The class has two overloaded `setInfo` member functions

4. The class also has a `displayInfo` member function that outputs the student's name, age,
andaddress using the stored member variables.

5. In the `main` function:


• An array `students` of `Student` objects is created with a size of 10.
• Information for each student is set using the `setInfo` functions and array indexing.
• A loop is used to iterate through each student in the `students` array:
• The `displayInfo` function is called for each student to display their information.

6. The program then returns 0 to indicate successful execution.

CODE:

OUTPUT:
RESULT:
The above program executes correctly and shows the address of the studentscorrectly as
given in the program as output perfectly.
PROGRAM-5
AIM:
To write a program in C++ to print the product of two numbers using friend function.

ALGORITHM:
1. The code defines a class named `Multiplication` with a private member variable `number`
oftype `int`.

2. The `Multiplication` class has a constructor that takes an integer parameter and initializes
the `number` member variable with the provided value.

3. There is a friend function `multiply` defined outside the class that takes two constant
references to `Multiplication` objects as parameters and returns the product of their
`number`values.

4. In the `main` function, the user is prompted to enter two numbers, which are stored in
integer variables `num1` and `num2`.

5. The `multiply` function is then called with `num1` and `num2` as arguments, and the
productis stored in the integer variable `product`.

6. Finally, the calculated product is displayed to the user using a formatted message.

CODE:
OUTPUT:

RESULT:
The above program gives the output of the 2 numbers multiplication correctly as perthe
given inputs.
LAB-3
PROGRAM-1
AIM:

Create a class called Distance with private members feet and inches.
• Use parameterized constructor to read the value of feet and inches.
• use member function display() to display the read value.
• Use operator fn + to add two distances using friend function.

ALGORITHM:

1. Define a class Distance with private properties feet and inches.


2. Constructor initializes feet and inches.
3. Method display() prints the distance in feet and inches.
4. Declare operator+ as a friend function for addition.
5. Define the operator+ function outside the class.
6. Calculate total feet and inches by adding corresponding values.
7. Adjust total inches if it's greater than or equal to 12.
8. Return a new Distance object with calculated total feet and inches.
9. Create instances of Distance (distance1 and distance2).
10.Add distance1 and distance2 using the overloaded + operator to get
totalDistance.
11. Display distance1, distance2, and totalDistance.

CODE:

OUTPUT:

RESULT:

In the above program we created a class called distance with private members
feet and inches. And the program ran successfully and the output was shown.
PROGRAM-2
AIM:

Get two strings. Check whether entered strings are equal using
operator overloading using member function.
ALGORITHM:

1. Define a class check with a private string property str.


2. Constructor initializes str with the provided string.
3. Method operator== compares str of current and other object.
4. Returns true if strings are equal, otherwise false.
5. Declare string variables str1 and str2.
6. Prompt user for two input strings.
7. Create check objects using entered strings.
8. Compare equality of check objects with == operator.
9. Display whether strings are equal or not.

CODE:

OUTPUT:

RESULT:

In the above program we gave 2 string and input and checked whether the 2
strings are equal or not using operator overloading, the program ran successfully
and the required output was shown.

PROGRAM-3
AIM:
Create a class Box having length, breadth and height as private data
members and count as static data member.
• The class uses a constant member function getvolume() to return the
product of length, breadth and height.
• The class uses static member function to return the count.

ALGORITHM:

1. Define a class Box with private properties length, breadth, and height.
2. Include a private static property count to keep track of the number of
instances created.
3. Implement a constructor to initialize dimensions and increment count.
4. Create a method getVolume() to calculate and return the volume of the
box.
5. Define a static method getCount() to retrieve the total count of boxes.
6. Initialize the static member variable count to 0 outside the class
definition.
7. Inside the main function:
• Create two instances of Box with specified dimensions.
• Calculate and display the volume of each box using the getVolume()
method.
Print the total count of boxes using the getCount() method
CODE:
OUTPUT:

RESULT:

In the above program we Created a class Box having length, breadth and height
as private data members and count as static data member, the program ran
successfully and the output was shown.
LAB-4
PROGRAM-1
AIM:

Create a class named Vehicle with two data member named mileage and price.
Create its subclass Car with datamembers to store ownership cost, warranty
(by years), seating capacity and fuel type (diesel or petrol). store and print the
information of a car (ownership cost, warranty, seating capacity, fuel type,
mileage, and price)

ALGORITHM:
• Create a class called vehicle with two member variables: mileage
and price.
• Implement a member function display() inside the vehicle class.
This function prompts the user to enter the details of the vehicle
(mileage and price) and stores the values in the respective member
variables.
• Create a class called car that inherits from the vehicle class.
• Inside the car class, add four additional member variables:
ownership_cost, warranty, seating_type, and fuel_type.
• Implement a member function show() inside the car class. This
function prompts the user to enter the details of the car(ownership
cost, warranty, seating type, and fuel type) and stores the values in
the respective member variables.
• In the main() function:
• Create an object c of the car class.
• Call the display() function on the c object to prompt the userfor the
vehicle details and store them in the mileage and price member
variables inherited from the vehicle class.
• Call the show() function on the c object to prompt the user for the
car details and store them in the ownership_cost, warranty,
seating_type, and fuel_type member variables defined in the car
class.
• Return 0 to indicate successful execution.

CODE:

OUTPUT:

RESULT:
The above program successfully stored and printed the details ofvehicle.

PROGRAM-2
AIM:

We want to calculate the total marks of each student of aclass in Physics,


Chemistry and Mathematics and the average marks of the class. The number of
students in the class is enteredby the user. Create a class named Marks with data
members forroll number, name, and marks. Create three other classes inheriting
the Marks class, namely Physics, Chemistry and Mathematics, which are used to
define marks in individual subject of each student. The roll number of each student
will begenerated automatically.

ALGORITHM:
a) Start the program.
b) Prompt the user to enter the number of students in the class.
c) Create arrays of objects of the Physics, Chemistry, and Mathematics
classes, with the size equal to the number of students entered by the
user.
d) Start a loop to get data for each student:
a. Get the name of the student using the getData() function of
the Physics class.
b. Generate the roll number for the student using the
generateRollNumber() function of the Physics class.
c. Get the marks in Physics for the student using the
getPhysicsMarks() function of the Physics class.
d. Get the name of the student using the getData() function of
the Chemistry class.
e. Generate the roll number for the student using the
generateRollNumber() function of the Chemistry class.
f. Get the marks in Chemistry for the student using the
getChemistryMarks() function of the Chemistry class.
g. Get the name of the student using the getData() function of
the Mathematics class.
h. Generate the roll number for the student using the
generateRollNumber() function of the Mathematics class.
i. Get the marks in Mathematics for the student using the
getMathMarks() function of the Mathematics class.

e) Display the class marks header.


f) Start a loop to display the marks of each student:
a. Display the roll number and name of the student usingthe
displayData() function of the Physics class.
b. Display the marks in Physics for the student using the
displayPhysicsMarks() function of the Physics class.
c. Display the roll number and name of the student usingthe
displayData() function of the Chemistry class.
d. Display the marks in Chemistry for the student using the
displayChemistryMarks() function of the Chemistry class.
e. Display the roll number and name of the student using the
displayData() function of the Mathematics class.
f. Display the marks in Mathematics for the student using the
displayMathMarks() function of the Mathematics class.
g) End the loop.
h) End the program.
:

CODE:
OUTPUT:
RESULT:

The above program has calculated the total, average of the class andare
displayed to the console as output
PROGRAM-3
AIM:

Create a class named Shape with a function that prints "This is a shape". Create
another class named Polygon inheritingthe Shape class with the same function
that prints "Polygon is a shape". Create two other classes named Rectangle
and Trianglehaving the same function which prints "Rectangle is a polygon"
and "Triangle is a polygon" respectively. Again, make another class named
Square having the same function which prints "Square is a rectangle".

Now, try calling the function by the object of each of theseclasses.

ALGORITHM:
• Start the program.
• Create a class named `Shape`.
o Declare a function named `printInfo()` within the
`Shape` class that prints "This is a shape".
• Create a class named `Polygon` inheriting from the `Shape`class.
o Declare a function named `printInfo()` within the
`Polygon` class that prints "Polygon is a shape".
• Create a class named `Rectangle` inheriting from the
`Polygon` class.
o Declare a function named `printInfo()` within the
`Rectangle` class that prints "Rectangle is a polygon".
• Create a class named `Triangle` inheriting from the
`Polygon` class.
o Declare a function named `printInfo()` within the
`Triangle` class that prints "Triangle is a polygon".
• Create a class named `Square` inheriting from the
`Rectangle` class.
o Declare a function named `printInfo()` within the
`Square` class that prints "Square is a rectangle".
• Start the `main()` function.
• Create an object `shape` of the `Shape` class.
• Create an object `polygon` of the `Polygon` class.
• Create an object `rectangle` of the `Rectangle` class.
• Create an object `triangle` of the `Triangle` class.
• Create an object `square` of the `Square` class.
• Call the `printInfo()` function for the `shape` object.
• Call the `printInfo()` function for the `polygon` object.
• Call the `printInfo()` function for the `rectangle` object.
• Call the `printInfo()` function for the `triangle` object.
• Call the `printInfo()` function for the `square` object.
• End the `main()` function.
• End the program.

CODE:

OUTPUT:
RESULT:

The above program has successfully overrided the method in base classand
also the function was overloaded.
LAB-5
PROGRAM-1
AIM:

Write a C++ program to print the address and value of thevariable.


ALGORITHM:

• Declare an integer variable 'num'.


• Assign a value (e.g., 10) to the variable 'num'.
• Print the message "Address of 'num': ".
• Print the address of the variable 'num' using the '&' operator.
• Print a newline character for formatting.
• Print the message "Value of 'num': ".
• Print the value of the variable 'num'.
• Return 0 to indicate successful execution.
CODE:

OUTPUT:

RESULT:

By above code Write a C++ program to print the address and value ofthe
variable
PROGRAM-6
AIM:

Write a C++ program to find the smallest of three numbers usingpointers.


ALGORITHM:
• Define a function findSmallest that takes three integer pointers ptr1, ptr2, and ptr3 as
arguments:
o Initialize a variable min with the value pointed to by ptr1 (*ptr1).
o If the value pointed to by ptr2 (*ptr2) is less than min, update min to *ptr2.
o If the value pointed to by ptr3 (*ptr3) is less than min, update min to *ptr3.
o Return the value of min.
• In the main function:
• Declare integer variables num1, num2, and num3.
• Print the message "Enter three numbers: ".
• Read and store the values of num1, num2, and num3.
• Create integer pointers ptr1, ptr2, and ptr3 and assign them the addresses of num1,
num2, and num3 respectively.
• Call the findSmallest function with ptr1, ptr2, and ptr3 as arguments and store the
result in the variable smallest.
• Print the message "The smallest number is: " followed by the value of smallest.
CODE:

OUTPUT:

RESULT:
The above code is to find the smallest of three numbers usingpointers.

PROGRAM-3
AIM:

Given String is AmritA. Convert uppercase to lowercase and viceversa using


pointers
ALGORITHM:

• Define a function convertCase that takes a pointer to a character array str


as an argument:
o Use a while loop to iterate through the characters in the string until
the null terminator '\0' is reached.
o For each character:
• Check if it's a lowercase letter (ASCII values between 'a' and 'z'):
- If true, convert it to uppercase by subtracting 32 from its ASCII
value.
• ii. Check if it's an uppercase letter (ASCII values between 'A' and 'Z'):
- If true, convert it to lowercase by adding 32 to its ASCII value.
• iii. Move the pointer to the next character in the string.
o End the loop.
• In the main function:
• Declare a character array str of size 100.
• Print the message "Enter a string: ".
• Read a line of input into the str array using cin.getline().
• Call the convertCase function with str as an argument.
• Print the message "String after case conversion: " followed by the
modified string str.
CODE:

OUTPUT:
RESULT:

By the above code we can print the given word into uppercase tolowercase
and vice versa.

PROGRAM-4
AIM:

Write a C++ program to print a number and name (Entered usingKeyboard)


using this pointer.

ALGORITHM:

• Declare an integer variable 'number'.


• Declare a string variable 'name'.
• Print the message "Enter a number: ".
• Read and store the input in the variable 'number'.
• Print the message "Enter a name: ".
• Ignore any leftover characters in the input buffer.
• Read a line of input (including spaces) and store it in the variable 'name' using
getline().
• Create an integer pointer 'ptrNumber' and assign it the address of 'number'.
• Create a string pointer 'ptrName' and assign it the address of 'name'.
• Print the value of 'number' using the pointer 'ptrNumber' and dereference it as
'*ptrNumber'.
• Print the value of 'name' using the pointer 'ptrName' and dereference it as '*ptrName'

CODE:
OUTPUT:

RESULT:

By the above code we can print a number and name (Entered usingKeyboard) using this
pointer.

PROGRAM-5
AIM:

Write a C++ program to print the elements of an array using pointer.

ALGORITHM:
• Define a constant integer 'size' to specify the size of the array (e.g., 5).
• Create an integer array 'arr' with 'size' elements and initialize it with some values.
• Create an integer pointer 'ptr' and point it to the first element of the array 'arr'.
• Print the message "Elements of the array:".
• Use a loop to iterate from 0 to 'size-1':
o Inside the loop:
• Print the message "Element i: " followed by the value pointed to by 'ptr' (*ptr).
• ii. Move the pointer 'ptr' to the next element in the array.
• End the loop.
CODE:

OUTPUT:
RESULT:

By the above code we can print the elements of an array usingpointer.

PROGRAM-6
AIM:

Write a function which will take pointer and display the number onscreen.
Take number from user and print it on screen using that function. ( Pointer to
Function)

ALGORITHM:
• Define a function displayNumber that takes an integer pointer ptr as an argument:
o Print the message "Number: " followed by the value pointed to by ptr (*ptr).
• In the main function:
• Declare an integer variable number.
• Print the message "Enter a number: ".
• Read and store the input in the variable number.
• Call the function displayNumber with the address of number (&number) as an
argument.
CODE:

OUTPUT:
RESULT:

By the above code we can Write a function which will take pointer and display
the number on screen. Take number from user and printit on screen using that
function.

LAB-6
PROGRAM-1
AIM:

Write a function template to find the average elements of an array. Pass the
entire array and its size as an argument to a function.

CODE:

OUTPUT:

RESULT:

By above code we write a function template to find the average


elements of an array. Pass the entire array and its size as an argument to a
function.
PROGRAM-2
AIM:

Write a function template to sort the elements using bubble sort.


CODE:

OUTPUT:

RESULT:

Hence the above code we can write a function template to sort the elements
using bubble sort.

PROGRAM-3
AIM:

Write a C++ program to implement the queue concept using class


templates.
CODE:
OUTPUT:

RESULT:
Hence the above program has been studies and executed successfully
PROGRAM-4
AIM:

You are given integers. Sort the integers and print the sorted order.Store
the integers in a vector. Vectors are sequence containers representing
arrays that can change in size.

Note: Use all the elements of STL in a program


CODE:

OUTPUT:
RESULT:

By the above code the numbers are sorted in an order.

PROGRAM-6
AIM:

Write an STL program to reverse the elements of linked list.


CODE:

OUTPUT:

RESULT:
by the above code we can write an STL program to reverse the elements of
linked list.
LAB-7
PYTHON
PROGRAM-1
AIM:

Calculate the area of a triangle using Heron’s formulaCode :

CODE:

OUTPUT:

RESULT:

By the above code we can calculate the area of a triangle usingHeron’s


formula

PROGRAM-2
AIM:

To compute the area of a right angled triangle with nonhypothesis sides a and b.
CODE:
OUTPUT:

RESULT:

By the above code we can compute the area of a right angledtriangle


with non hypothesis sides a and b.

PROGRAM-3
AIM:

To print the value of x for the given program where x = -10Code

CODE:

OUTPUT:

RESULT:

By the above code we can print the print value of x for the givenprogram where x
= -10

PROGRAM-4
AIM:

To input a number and find the sum of digit using while loop.
CODE:
OUTPUT:

RESULT:

By the above code we can input a number and find the sum ofdigit using
while loop

PROGRAM-5
AIM:

To generate calendar of a month given the start day and number of days
CODE:

OUTPUT:
RESULT:

By the above code we can generate calendar of a month giventhe start


day and number of days

PROGRAM-6
AIM:

To find LCM of two numbers using do while loop in python.


CODE:

OUTPUT:

RESULT:

By the above code we can find LCM of two numbers using dowhile loop
in python

PROGRAM-7
AIM:

To write a python program using if else for givenscenario.


CODE:
OUTPUT:

RESULT:

By the above code we can write a python program using if elseelse if for
given scenario.

SWITCH CASE:
AIM:

To write python code to execute the same scenario usingswitch case .


CODE:

OUTPUT:
RESULT:

By the above code we can write python code to execute thesame scenario using
switch case
LAB-8
PROGRAM-1
AIM:

Count the occurrence of string s2 in s1Code


CODE:

OUTPUT:

RESULT:

By the above code we can Count the occurrence of string s2 ins1.

PROGRAM-2
AIM:

Remove all special characters other than digits and characters


CODE:

OUTPUT:

RESULT:
By the above code we can Remove all special characters otherthan digits and
characters
PROGRAM-3
AIM:

Remove repeated characters in a string.Code


CODE:

OUTPUT:

RESULT:

By the above code we can Remove repeated characters in astring.

PROGRAM-4
AIM:

Get the first two and last two characters of a stringCode


CODE:

OUTPUT:

RESULT:

By the above code we can Get the first two and last twocharacters of a string
PROGRAM-5
AIM:

Find all pairs of combinations of two tuples.


CODE:
OUTPUT:

RESULT:

By the above code we can Find all pairs of combinations of twotuples


PROGRAM-6
AIM:

Convert a tuple of lists to a single tuple.


CODE:

OUTPUT:

RESULT:

By the above code we can Convert a tuple of lists to a singletuple.

Aim :

Merge two dictionaries

Code :
Output :

Result :
By the above code we can Merge two dictionaries.

PROGRAM-1
Aim :
Combine two dictionaries by adding values for commonkeys.
Code :

Output :

Result :
By the above code we can Combine two dictionaries by addingvalues for
common keys.

PROGRAM-2
Aim :
Create a list from a tuple and vice versa.
Code :

Output :

Result :
By the above code we can Create a list from a tuple and viceversa.

PROGRAM-3
Aim :
Calculate the bill based on a dictionary of productspurchased and their
MRPs.
Code :
Output :

Result :
By the above code we can Calculate the bill based on adictionary of
products purchased and their MRPs.

PROGRAM-4
Aim :
Find the maximum and minimum values in adictionary
Code :

Output :

Result : By the above code we can Find the maximum and minimumvalues in a
dictionary

PROGRAM-5
Aim :
Print "Hello World" with the first letter capitalized.
Code :

Output :

Result :
By the above code we can Print "Hello World" with the firstletter
capitalized.

PROGRAM-6
Aim :
Toggle the case of characters in a string
Code :

Output :

Result :
By the above code we can Toggle the case of characters in astring.
PROGRAM-7
Aim :
Print "Hello Friends" by replacing "world".
Code :

Output :

Result :
By the above code we can Print "Hello Friends" by replacing"world".

PROGRAM-8
Aim :
Encrypt a message by adding a key value to everycharacter.
Code :

Output :

Result :
By the above code we can Encrypt a message by adding a keyvalue to
every character.

Lab 9
PROGRAM-1
Aim :
Program to find the product of two integers using afunction
Code :

Output :

Result :
By the above code we can Program to find the product of twointegers
using a function.
PROGRAM-2
Aim :
Program to swap two strings using a function.Code :
Output :

Result :
By the above code we can Program to swap two strings using afunction.

PROGRAM-3
Aim :
Program to find perfect numbers between 1 and 1000using a function.
Code :

Output :
Result :
By the above code we can Program to find perfect numbersbetween 1
and 1000 using a function.

PROGRAM-4
Aim :
Program to find the length of the string "refrigerator"without using len
function.
Code :

Output :

Result :
By the above code we can Program to find the length of thestring
"refrigerator" without using len function.

PROGRAM-5
Aim :
Program to create a new string with consonants deletedfrom "Hello, have a
good day".
Code :
Output :

Result :
By the above code we can create a new string with consonantsdeleted
from "Hello, have a good day".

PROGRAM-6
Aim :
Program to find the sum of all even numbers in a set usinga function.
Code :

Output :

Result :
By the above code we can find the sum of all even numbers in aset using a
function.
PROGRAM-7
Aim :
Program to split a list of 10 elements into two differentlists.
Code :

Output :

Result :
By the above code we can split a list of 10 elements into twodifferent
lists.

PROGRAM-8
Aim :
Program to calculate factorials and store them in adictionary.
Code :
Output :

Result :
By the above code we can Program to calculate factorials andstore them
in a dictionary.
PROGRAM-9
Aim :
Program to count occurrences of each letter in the word
"MISSISSIPPI" using a function and store them in a dictionary

Code :

Output :

Result:
By the above code we can count occurrences of each letter inthe word
"MISSISSIPPI" using a function and store them in a dictionary.

PROGRAM-10
Aim :
Program to create a tuple from user-given eveninteger inputs and
print them as a list
Code :

Output :

Result:
By the above code we can Program to create a tuple from user-given even
integer inputs and print them as a list.

PROGRAM-11
Aim :
Program to calculate exp(x, y) using recursivefunctions.
Code :
Output :

Result:
By the above code we can calculate exp(x, y) using recursivefunctions.

PROGRAM-12
Aim :
Program to implement the Tower of Hanoi problemusing a recursive
function.
Code :
Output :

Result:
By the above code we can implement the Tower of Hanoiproblem using
a recursive function.

Lab 10
PROGRAM-1
Aim :
Write a program that has class Cars. Create two objectsand set Car1to be a red
convertible with price 10 lakhs and name Pugo.Car2to be a blue sedan named
Mavoworth 6
Lakh
Code
:
Output :

Result:
By the above code we can Write a program that has class Cars.Create two
objects and set Car1to be a red convertible with price 10 lakhs and name
Pugo.Car2to be a blue sedan named Mavoworth 6 lakhs
PROGRAM-2
Aim :
Write a program to compare length of 2 strings using
_cmp_ function.
Code :

Output :

Result:
By the above code we can Write a program to compare lengthof 2 strings
using _cmp_ function.

PROGRAM-3
Aim :
Make a class triangle. Enter its three sides andcalculate its area.
Code :
Output :

Result:
By the above code we can Make a class triangle. Enter its threesides and
calculate its area.
PROGRAM-4
Aim :
Write a program that uses a class attribute to define some default titles for
faculty in a college. Display the namealong with title and department of the
college.
Code :
Output :

Result:
By the above code we can Write a program that uses a class attribute to
define some default titles for faculty in a college.
Display the name along with title and department of thecollege.

PROGRAM-5
Aim :
Write a program that has a class pointwith attributes asthe X and Y co-
ordinates. Make two objects of this class and find the midpoint of both the points
Code :

Output :

Result:
By the above code we can Write a program that has a class pointwith
attributes as the X and Y co-ordinates. Make two objects of this class
and find the midpoint of both the points

PROGRAM-6
Aim :
Write a program to deposit or withdraw money in abank account.
Code :
Output :

Result:
By the above code we can Write a program to deposit orwithdraw
money in a bank account.

Lab 11
PROGRAM-1
Aim :
Write a program for a publishing company that markets books
and CDs. Write a class Publication that stores title and price. Derive a
class Book which hasan additional member as number of pages. Derive
another class Lecture from Publication with additionalmember play time.
Create objects and display outputs accordingly
Code :
Output :

Result:
By the above code we can Write a program for a publishing
company that markets books and CDs. Write a class Publicationthat stores
title and price. Derive a class Book which has
an additional member as number of pages. Derive anotherclass
Lecture from Publication with additional member play time. Create
objects and display outputs accordingly

PROGRAM-2
Aim :
MULTIPLE.Define a class student with data membersas ID
number and name. Define a class Grade that has data member
CGPA. Derive a class scholarship which is derived from both
these classes to compute scholarship as follows: Rs.10,000/-pm
if CGPA>9. Rs.7500/-pm
ifCGPA>8. Rs.5000/-pm if CGPA>7.5.
Create an object of scholarship and display. in python
Code :

Output :
Result:
By the above code we can Define a class student with data
members as ID number and name. Define a class Grade that has data
member CGPA. Derive a class scholarship which isderived from
both these classes to compute scholarship asfollows: Rs.10,000/-pm
if CGPA>9. Rs.7500/-pm ifCGPA>8.
Rs.5000/-pm if CGPA>7.5. Create an object of scholarship and
display. in python

PROGRAM-3
Aim :
Inheritance”. Define a class which has two objects ofanother class. Create a
class Point with members as x, y
coordinates. Create another class Location that has objects
source and destination of class Point. Computethe distance
between these locations and print the distance in python
Code :

Output :
Result:
By the above code we can Define a class which has two objectsof
another class. Create a class Point with members as x, y
coordinates. Create another class Location that has objectssource and
destination of class Point. Compute the distancebetween these locations
and print the distance in python

PROGRAM-4
Aim :
MULTI-PATH. Create a base class Familywith
member surname. Create a derived class 1 Fatherwith father name
and occupation. Create another derived class2 Motherwith mother
name and age. Create a Derivedclass 3 childfrom Fatherand
Motherwith additional
member of child name. Create an object of child andprintthe
details of the family members in python with output
Code :
Output :

Result:
By the above code we can Create a base class Familywith
member surname. Create a derived class 1 Fatherwith fathername and
occupation. Create another derived class 2
Motherwith mother name and age. Create a Derived class3
childfrom Fatherand Motherwith additional member of
child name. Create an object of child and printthe details ofthe family
members in python with output

PROGRAM-5
Aim :
Write a program that has an Abstract class Polygon. Derive Threeclasses
Rectangle, Square and
Triangle from Polygon. Write methods to get the details oftheir
dimensions and then calculate the surface area. in python
Code :
Output :
Result:
By the above code we can Write a program that has an
Abstract class Polygon. Derive Threeclasses Rectangle, Squareand
Triangle from Polygon. Write methods to get the details of their
dimensions and then calculate the surface area. i

You might also like