0% found this document useful (0 votes)
9 views7 pages

ASSIGNMENT NO.2

The document outlines an assignment to develop a C++ program for creating a student database, including various student information such as name, roll number, and contact details. It details the use of C++ concepts like constructors, destructors, dynamic memory allocation, and exception handling. The provided code implements these features through classes and member functions, allowing for the addition and display of student records.

Uploaded by

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

ASSIGNMENT NO.2

The document outlines an assignment to develop a C++ program for creating a student database, including various student information such as name, roll number, and contact details. It details the use of C++ concepts like constructors, destructors, dynamic memory allocation, and exception handling. The provided code implements these features through classes and member functions, allowing for the addition and display of student records.

Uploaded by

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

ASSIGNMENT NO.

2
TITLE: Program to create Students Database using C++ Concepts
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

CODE
#include<iostream>
#include<string.h>
using namespace std;

class StudData;

class Student{
string name;
int roll_no;
string cls;
char* division; //pointer datamember or pointer variable
string dob;
char* bloodgroup;
static int count;

public:
Student() // Default Constructor
{
name="";
roll_no=0;
cls="";
division=new char; //dynamic memory allocation operator-new
dob="dd/mm/yyyy";
bloodgroup=new char[4];
}

Student(Student *obj)
{
cout<<"\nCopy constructor implemented"<<endl;
}

~Student() // Destructor
{
delete division; //dynamic memory allocation operator-delete
delete[] bloodgroup;
}

static int getCount() // static member function


{
return count;
}

void getData(StudData*);
void dispData(StudData*);
};

class StudData{
string caddress;
long int* telno;
long int* dlno;
friend class Student; //friend class

public:

StudData()
{
caddress="";
telno=new long;
dlno=new long;
}

~StudData()
{
delete telno;
delete dlno;
}

void getStudData()
{
cout<<"Enter Contact Address : ";
cin.get();
getline(cin,caddress);
cout<<"Enter Telephone Number : ";
cin>>*telno;
cout<<"Enter Driving License Number : ";
cin>>*dlno;
}

void dispStudData()
{
cout<<"Contact Address : "<<caddress<<endl;
cout<<"Telephone Number : "<<*telno<<endl;
cout<<"Driving License Number : "<<*dlno<<endl;
}
};

inline void Student::getData(StudData* st) //inline code


{
cout<<"Enter Student Name : ";
getline(cin,name);
cout<<"Enter Roll Number : ";
cin>>roll_no;
cout<<"Enter Class : ";
cin.get();
getline(cin,cls);
cout<<"Enter Division : ";
cin>>division;
cout<<"Enter Date of Birth : ";
cin.get();
getline(cin,dob);
cout<<"Enter Blood Group : ";
cin>>bloodgroup;
st->getStudData(); //another class function call with local st pointer
count++;
}

inline void Student::dispData(StudData* st1)


{
cout<<"Student Name : "<<name<<endl;
cout<<"Roll Number : "<<roll_no<<endl;
cout<<"Class : "<<cls<<endl;
cout<<"Division : "<<division<<endl;
cout<<"Date of Birth : "<<dob<<endl;
cout<<"Blood Group : "<<bloodgroup<<endl;
st1->dispStudData();
}
int Student::count;//need to define static member to tell compiler which
member
//present in which class.

int main()
{
Student* stud1[100]; //array of pointer or pointer array to create n
//number of objects.
StudData* stud2[100];
int n=0; //number of students
char ch;

do
{
stud1[n]=new Student;
stud2[n]=new StudData;
stud1[n]->getData(stud2[n]); //n number of pointers to point n
number of //objects.(-> member access
operator)
n++;
cout<<"Do you want to add another student (y/n) : ";
cin>>ch;
cin.get();
} while (ch=='y' || ch=='Y');

for(int i=0;i<n;i++)
{
cout<<"---------------------------------------------------------------"<<endl;
stud1[i]->dispData(stud2[i]);
}

cout<<"---------------------------------------------------------------"<<endl;
cout<<"Total Students : "<<Student::getCount();
cout<<endl<<"---------------------------------------------------------------"<<endl;

for(int i=0;i<n;i++) //delete created objects


{
delete stud1[i];
delete stud2[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