Skip to main content

OOP 2

Object Oriented Programming

Group A -

Practical : 2

Problem Statement : Develop a program in C++ to create a database of student’s information system containing the following information: Name, Roll number, Class, Division, Date of Birth, Blood group, Contact address, Telephone number, Driving license no. and other. Construct the database with suitable member functions. Make use of constructor, default constructor, copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete as well as exception handling.

Check Out Code Here 👇

#include <iostream>
#include<string.h>
using namespace std;
class student
{
public:
int roll_no;
char clas[10];
int sr_no;
long int tele_no;
char name[20];
char div;
char blood_grp;
char DOB[10];
static int count;
void getdata();
friend void display(student & obj);
student() //Constructor
{
roll_no=0;
roll_no=count;
count++;
}
~student() //Destructor
{
cout<<"\nDestroying the object";
count--;
}
student(int roll_no)
{
this->roll_no=roll_no;
}
student (student & obj)
{
roll_no=obj.roll_no;
strcpy(name,obj.name);
strcpy(DOB,obj.DOB);
strcpy(clas,obj.clas);
blood_grp=obj.blood_grp;
div=obj.div;
tele_no=obj.tele_no;
sr_no=count;
count++;
}
};
int student :: count=0;
void student:: getdata()
{
cout<<"\n"<<"Enter the roll number of the student : ";
cin>>roll_no;
cout<<"\n"<<"Enter the name of the student : ";
cin>>name;
cout<<"\n"<<"Enter the date of birth of the student : ";
cin>>DOB;
cout<<"\n"<<"Enter the blood group of the student : ";
cin>>blood_grp;
cout<<"\n"<<"Enter the class of the student : ";
cin>>clas;
cout<<"\n"<<"Enter the division of the student : ";
cin>>div;
cout<<"\n"<<"Enter the contact of the student : ";
cin>>tele_no;
}
void display(student & obj)
{
cout<<"\n"<<obj.roll_no;
cout<<"\t\t"<<obj.name;
cout<<"\t"<<obj.DOB;
cout<<"\t"<<obj.blood_grp;
cout<<"\t\t"<<obj.clas;
cout<<"\t"<<obj.div;
cout<<"\t\t"<<obj.tele_no;
}
int main()
{
student s1;
student s2(s1);
cout<<"\n Enter the details of a student :"<<"\n";
s1.getdata();
cout<<"All data is as displayed below :"<<"\n";
cout<<"\n-------------------------------------------------------------------------------------";
cout<<"\nROLL NUMBER\tNAME\tDOB\tBLOOD GRP\tCLASS\tDIVISION\tCONTACT NUMBER\n";
display(s1);
cout<<"\n-------------------------------------------------------------------------------------\n";
int i,n;
student *s[50];
cout<<"\nEnter how many student object do you want us to create?"<<"\n";
cin>>n;
for(i=0;i<n;i++)
{
s[i]= new student();
}
for(i=0;i<n;i++)
{
cout<<"\n--------------Constructor--------------\n";
s[i]->getdata();
}
cout<<"\n---------------------------------------------------------------------";
cout<<"\nROLL NUMBER\tNAME\tDOB\tBLOOD GRP\tCLASS\tDIVISION\tCONTACT NUMBER\n";
for(i=0;i<n;i++)
{
display(*s[i]);
}
cout<<"\n---------------------------------------------------------------------\n";
for(i=0;i<n;i++)
{
cout<<"\n"<<"--------------Destructor--------------";
delete (s[i]);
}
return 0;
}
Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊

Comments

Popular posts from this blog

DSL A1

Hello Friends lets See the first practical of Data Structure Laboratory(DSL) of SPPU Second Year. Some of the students are afraid of coding as it is new to all of us. So we are here to conquer your fear. You will find it easy as it explained by students only. So lets Get into it The first practical of part A is : In second year computer engineering class, group A student’s play cricket, group B students play badminton and group C students play football. Write a Python program using functions to compute following: -  a) List of students who play both cricket and badminton  b) List of students who play either cricket or badminton but not both  c) Number of students who play neither cricket nor badminton  d) Number of students who play cricket and football but not badminton.  (Note- While realizing the group, duplicate entries should be avoided, Do not use SET built-in functions)  So most of us know the SET theory in mathematics. The above problem is very easy...

OOP 6

   Object Oriented Programming Group B - Practical : 6 Problem Statement :  Write C++ program using STL for sorting and searching user defined records such as personal records (Name, DOB, Telephone number etc) using vector container. Check Out Code Here  👇 Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊