Experiment Number - 2.3: Aim of The Experiment - 7.1
Experiment Number - 2.3: Aim of The Experiment - 7.1
FLOWCHART/ALGORITHM
Start
Create a class Records. Declare some required variables such as name and
age.
Variables will be private.
These variables will be accessed by the member functions of the class
Records.
Now we will create a constructor which will initialize the variables with
their required values.
The constructor which we will create will be a parameterized constructor.
Now we will define a functions whose return type will be Records.
In the function we will check whose age is greater and will be printed that
age.
In the function we will use ternary operator to find out the greatest of them
by using ‘this’ pointer that will hold the position of the greater age and then
again compare with the next age.
PROGRAM CODE:-
#include<iostream>
class Records
int age;
string name;
public:
Records() {};
void show()
cout<<name<<" : "<<age<<endl;
Records eldest(Records o)
{
return (o.age>age)? o: *this;
};
int main()
{
cout<<"SAKSHI KUMARI 21BCS9402"<<endl;
Records ob[3]={Records("Ani",21),Records("Arka",50),Records("Ram",30)};
Records res;
for(int i=0;i<2;i++)
res = ob[i].eldest(ob[i+1]);
res.show();
return 0;
PROGRAMS’EXPLANATION
The records of person with details (Name and Age) and find the eldest among them. The
program must use this pointer to return the result by overloading> operator among two
objects.
OUTPUT:-
FLOWCHART/ALGORITHM –
Include the required header files (iostream.h and conio.h).
Create a class (Student) with the following class members as public
members.
stud_name, marks as data members.
getStudentInfo() and displayStudentInfo() as member functions.
Implement the getStudentInfo() and displayStudentInfo() member
functions.
Create a main() method.
Create an array of stud object wigth max size and a pointer object of
Student class.
Assign base address of object array to pointer object and make function
calls to getStudentInfo() and displayStudentInfo() using class pointer
object
PROGRAM CODE:
#include <iostream>
class Number
private:
int num;
public:
//constructor
Number(){ num=0; };
cin>>num;
void displayNumber()
cout<<"Num: "<<num<<endl;
};
//Main function
int main()
{
cout<<"SAKSHI KUMARI 21BCS9402"<<endl;
//declaring object to the class number
Number N;
N.inputNumber();
N.displayNumber();
Number *ptrN;
ptrN->displayNumber();
ptrN->inputNumber();
ptrN->displayNumber();
return 0;
}
PROGRAMS’EXPLANATION
C++ allows us to create a class with its members such as data members and
member functions. One way to access the data members and member function
of a class is through the object of the class with a dot operator. C++ also
provides us a few operators through we could access the data members and
member functions of a class by using pointers. These operators are known as
dereferencing operators.
NO ERROR |
OUTPUT:
AIM OF THE EXPERIMENT– 7.3
WAP to design a class representing the information regarding digital library
(books, tape: book & tape should be separate classes having the base class as
media).The class should have the functionality for adding new item, issuing,
deposit etc. The program should link the objects with concerned function by the
concept of runtime polymorphism
FLOWCHART/ALGORITHM –
1. Start
2. Create a class Records. Declare some required variables such as name and age.
3. Variables will be private.
4. These variables will be accessed by the member functions of the class Records.
5. Now we will create a constructor which will initialize the variables with their
required values.
6. The constructor which we will create will be a parameterized constructor.
7. Now we will define a functions whose return type will be Records.
8. In the function we will check whose age is greater and will be printed that age.
9. in the function we will use ternary operator to find out the greatest of them by
using ‘this’ pointer that will hold the position of the greater age and then again
compare with the next age
PROGRAM CODE:
#include<iostream>
#include<string.h>
class media
protected:
char title[50];
float price;
public:
};
pages = p;
void display();
};
time =t;
void display();
};
cout<<"\n Title:"<<title;
cout<<"\n Pages:"<<pages; cout<<"\n Price:"<<price;
cout<<"\n Title:"<<title;
int main()
{
cout<<"SAKSHI KUMARI 21BCS9402"<<endl;
int pages;
cout<<"\n Title:";
cin>>title;
cout<<"\n Price:";
cin>>price;
cin>>time;
media* list[2];
list[0] = &book1;
cout<<"\n..............Book. ";
list[0]->display ();
cout<<"\n..............Tape. ";
list[1]->display ();
return 0;
PROGRAMS’EXPLANATION
A class representing the information regarding digital library (books, tape: book
& tape should be separate classes having the base class as media). The class
should have the functionality for adding new item, issuing, deposit etc. The
program should link the objects with concerned function by the concept of
runtime polymorphism.
OUTPUT:
LEARNING OUTCOMES