C++ programs
Each lab has some questions given for practice
Codes in each file :
LAB 1
1.Write a Program To pass an entire array to a function.Print all the elements and Return the largest element
2.Write a Program To pass a student name,roll no and average marks as function array and print all the details in user defined function
3.Write a Program To create a function that calculate rate of interest and return the value to the calling function
LAB 2
1.Write a program to overload the function area to compute area of rectangle, circle and square
- Write a program to allocate n spaces dynamically to allocate for integers. Enter values and find the sum and average. The value of n is enter by user from keyboard.
LAB 3
1.Write a program in c++to create a class to show the use of static and non static data members and member functions.
2.Write a program in C++to create a class to show overloading of member functions where make one member function as online and another as non online.
3.Write a program to create a class student having roll, and 5 subject marks. Input and display the details of two students along with average mark.
LAB 4
- WAP to swap private data member of two classes. [The classes have no relation with each other].
2.Create two classes which stores distance in feet, inches and meter, centimeter format respectively. Write a function which compares distance in object of these classes and displays the larger one.
3.Create a class with an integer data member. Include functions for input and output in class. Count the number of times each function is called and display it.
4.Create a class which stores name, roll number and total marks for a student. Input data for n students. Find the average marks scored by n students, store it as a data member of the class and display it using a function which may be called without object.
5.Create a class which stores name, author and price of a book. Store information for n number of books. Display information of all the books in a given price range using friend function.
LAB 5
1.Create a class complex which stores real and imaginary part of a complex number.Include all types of constructors and destructor. The destructor should display a message about the destructor being invoked. Create objects using different constructors and display them.
-
Create a class which stores time in hh:mm format. Include all the constructors. The parameterized constructor should initialize the minute value to zero, if it is not provided.
-
Create a class which stores a string and its length as data members. Include all the constructors. Include a member function to join two strings and display the concatenated string.
-
WAP to demonstrate the order of call of constructors and destructors for a class.
-
WAP to count number of objects created from a class using concept of static data members and static member function.
LAB 6
1..Create a class distance which stores a distance in feet and inches. Input 2 distance values in objects, add them, store the resultant distance in and object and display it. [Write the above program in two ways. a) store the resultant distance in the calling object:C3.add(C1,C2) b) return the resultant object C3=C1.add(C2)]
2.Write a program in C++ to derive a class “grade” from student which has four subject marks, name and roll number of a student.The “student” class stores the section,age of the student as its private member. Input the details for two students and print all the details with average mark.( The derived class is to be derived in private mode)
LAB 7
1.Write a program to create a class students having average marks as it's data member.Create two object and add user defined values entered by user from keyboard and add to both the object separately and display them by overloading binary plus operator and display them.
2.Write a program to create a class students having average marks as it's data member.Create two object and add user defined values entered by user from keyboard and add to both the object separately and display them by overloading binary plus operator and display them.Perform using friend function
-
.Write a program to create a class students having average marks as it's data member.Add these properties of one object to another object by using member and friend function and display them
-
Write a program to create a class students having average marks as it's data member. Overload binary plus operator to add two objects and store results to another object using member and friend function
LAB 8
-
WAP to overload following operators for class distance, which stores the distance in feet and inches. a)Overload Binary + to add two objects (D3=D1+D2) b)Add an object to an integer, where the integer should be added to the inches value ( D2=4+D1) c)Overload Unary - to show the new sign of values.
-
Create a class to store an integer array. Overload insertion and extraction operator to input and display the array elements.
-
Create a class which a complex number. Add two objects and display the resultant object.Overload the ++ (post and pre) operator for the class.
-
Create a class which allocates the memory for a string through dynamic constructor. Overload the binary + to concatenate two strings and display it.
5.WAP to add two objects of time class. Overload the operator ‘==’ to compare two objects and display whether they are equal or not. Overload the assignment operator to assign one property to another and display the time.
6.WAP to add two objects of distance class. Overload the operator > to compare two objects and return the object with larger time value and display it. Overload the == operator to compare and display whether two given objects contain same distance value.
LAB 9
1.WAP to display content of a file using character output function.
2.WAP to copy contents of one file to another.
3.WAP to write 10 strings into a file and display them from file.
4.WAP to display content of a file in reverse order.
- WAP to count following in a given file: a)No.of characters b)No.of words c)No.of lines d)No.of uppercase letters,lowercase letters, digits and special symbols.
6.WAP to read and write objects to a file,using read and write functions.
