0% found this document useful (0 votes)
3 views4 pages

Practical 5

Uploaded by

Arpita Siddhanti
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)
3 views4 pages

Practical 5

Uploaded by

Arpita Siddhanti
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/ 4

PRACTICAL:-5

 Develop an object oriented program in C++ to create a database of student information


system containing
 the following information: Name, Roll number, Class, division, Date of Birth, Blood group,
Contact
 address, telephone number, driving licence no. etc Construct the database with suitable
member functions
 for initializing and destroying the data viz constructor, default constructor, Copy constructor,
destructor,
 static member functions, friend class, this pointer, inline code and dynamic memory
allocation
 operators-new and delete.

Programe:-
#include <iostream>
#include <cstring>
using namespace std
class Student {
private:
char *name;
int rollNumber;
string studentClass;
char division;
string dob;
string bloodGroup;
string contactAddress;
long long telephoneNumber; // Changed from 'long' to 'long long'
string drivingLicenceNo;
public:
// Static member to keep count of students
static int studentCount;

// Default constructor
Student() {
name = new char[1];
strcpy(name, "");
rollNumber = 0;
division = ' ';
telephoneNumber = 0;
studentCount++;
}
// Parameterized constructor
Student(const char* n, int roll, string cls, char div, string dateOfBirth, string bg, string address, long
long phone, string dlNo) {
name = new char[strlen(n) + 1];
strcpy(name, n);
rollNumber = roll;
studentClass = cls;
division = div;
dob = dateOfBirth;
bloodGroup = bg;
contactAddress = address;
telephoneNumber = phone;
drivingLicenceNo = dlNo;
studentCount++;
}

// Copy constructor
Student(const Student &s) {
name = new char[strlen(s.name) + 1];
strcpy(name, s.name);
rollNumber = s.rollNumber;
studentClass = s.studentClass;
division = s.division;
dob = s.dob;
bloodGroup = s.bloodGroup;
contactAddress = s.contactAddress;
telephoneNumber = s.telephoneNumber;
drivingLicenceNo = s.drivingLicenceNo;
studentCount++;
}

// Destructor
~Student() {
delete[] name;
studentCount--;
}

// Friend class for special access


friend class Admin;
// Inline member function to display student info
inline void display() const {
cout << "Name: " << name << endl;
cout << "Roll Number: " << rollNumber << endl;
cout << "Class: " << studentClass << endl;
cout << "Division: " << division << endl;
cout << "Date of Birth: " << dob << endl;
cout << "Blood Group: " << bloodGroup << endl;
cout << "Contact Address: " << contactAddress << endl;
cout << "Telephone Number: " << telephoneNumber << endl;
cout << "Driving Licence No: " << drivingLicenceNo << endl;
}

// Static member function to display student count


static void displayStudentCount() {
cout << "Total number of students: " << studentCount << endl;
}
// This pointer demonstration
void updateContactDetails(const string& newAddress, long long newPhone) {
this->contactAddress = newAddress;
this->telephoneNumber = newPhone;
}
};

// Initialize static member


int Student::studentCount = 0;

// Friend class for special access to Student class private members


class Admin {
public:
void modifyStudentRecord(Student &s, const char* newName, int newRoll) {
strcpy(s.name, newName);
s.rollNumber = newRoll;
cout << "Student record modified successfully." << endl;
}
};

int main() {
// Creating dynamic memory for students
Student *s1 = new Student("John Doe", 101, "12th", 'A', "15-05-2005", "O+", "123 Street, City",
9876543210LL, "DL123456"); // Use 'LL' suffix for large constants

// Display student info


cout << "Student 1 Info:" << endl;
s1->display();

// Displaying student count using static member function


Student::displayStudentCount();

// Copy constructor demonstration


Student s2 = *s1;
cout << "\nCopy of Student 1 (Student 2) Info:" << endl;
s2.display();

// Friend class modifying student record


Admin admin;
admin.modifyStudentRecord(s2, "Jane Smith", 102);
cout << "\nModified Student 2 Info:" << endl;
s2.display();

// Demonstrating this pointer and updating contact details


s1->updateContactDetails("456 Avenue, City", 9123456789LL); // Use 'LL' suffix for large numbers
cout << "\nUpdated Contact Details of Student 1:" << endl;
s1->display();

// Freeing dynamically allocated memory


delete s1;
// Displaying student count after deletion
Student::displayStudentCount();

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