0% found this document useful (0 votes)
22 views3 pages

A 2 Database

This C++ program defines a student class with data members like roll number, name, date of birth etc. It includes constructor, destructor and member functions to get and display student details. The main function creates student objects, gets data and displays it by calling member functions. It allocates memory dynamically for multiple student objects and deletes them after use.

Uploaded by

dipak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

A 2 Database

This C++ program defines a student class with data members like roll number, name, date of birth etc. It includes constructor, destructor and member functions to get and display student details. The main function creates student objects, gets data and displays it by calling member functions. It allocates memory dynamically for multiple student objects and deletes them after use.

Uploaded by

dipak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#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;
cout << "\tConstructor";
roll_no = count;
count++;
}

~student() // Destructor
{
cout << "\nDestructor";
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" << obj.name;
cout << "\t" << obj.DOB;
cout << "\t" << obj.blood_grp;
cout << "\t" << obj.clas;
cout << "\t" << obj.div;
cout << "\t" << obj.tele_no;
}

int main()
{

student s1;
student s2(s1);
cout << "\n Enter the details of a student:"<< "\n";

s1.getdata();

cout << "\


n---------------------------------------------------------------------";
cout << "\nROLL NUMBER\tNAME\tDOB\tBLOOD GRP\tCLASS\tDIVISION\tCONTACT NUMBER";
display(s1);
cout << "\
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++)


{
s[i]->getdata();
}

for (i = 0; i < n; i++)


{
display(*s[i]);
}

for (i = 0; i < n; i++)


{
delete (s[i]);
}
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy