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

OOPp 2

Uploaded by

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

OOPp 2

Uploaded by

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

#include <iostream>

#include <string>

#include <stdexcept>

using namespace std;

class Student {

private:

string name;

int rollNumber;

string className;

char division;

string dateOfBirth;

string bloodGroup;

string contactAddress;

string telephoneNumber;

string drivingLicenseNo;

public:

// Default constructor

Student() : name(""), rollNumber(0), className(""), division(' '),

dateOfBirth(""), bloodGroup(""), contactAddress(""),

telephoneNumber(""), drivingLicenseNo("") {}

// Parameterized constructor

Student(string n, int r, string c, char d, string dob, string bg, string addr, string tel, string dl): name(n),
rollNumber(r), className(c), division(d),

dateOfBirth(dob), bloodGroup(bg), contactAddress(addr), telephoneNumber(tel),


drivingLicenseNo(dl)
{

// Copy constructor

Student(const Student &s)

name = s.name;

rollNumber = s.rollNumber;

className = s.className;

division = s.division;

dateOfBirth = s.dateOfBirth;

bloodGroup = s.bloodGroup;

contactAddress = s.contactAddress;

telephoneNumber = s.telephoneNumber;

drivingLicenseNo = s.drivingLicenseNo;

// Destructor

~Student()

// Clean up if needed (not required here since we're using strings)

// Static member function

static void printWelcomeMessage()

cout << "Welcome to the Student Information System!" << endl;

}
// Member function to display student information

void displayInfo() const

cout << "Name: " << name << endl;

cout << "Roll Number: " << rollNumber << endl;

cout << "Class: " << className << endl;

cout << "Division: " << division << endl;

cout << "Date of Birth: " << dateOfBirth << endl;

cout << "Blood Group: " << bloodGroup << endl;

cout << "Contact Address: " << contactAddress << endl;

cout << "Telephone Number: " << telephoneNumber << endl;

cout << "Driving License No: " << drivingLicenseNo << endl;

// Friend function to modify private members (for demonstration)

friend void updateStudentInfo(Student &s, const string &newName);

};

void updateStudentInfo(Student &s, const string &newName) {

s.name = newName;

int main()

Student::printWelcomeMessage();

try

// Dynamic memory allocation

Student* student1 = new Student("John Doe", 1, "10th", 'A', "01-01-2005", "O+", "123 Elm St",
"123-456-7890", "D1234567");
student1->displayInfo();

// Update student info using friend function

updateStudentInfo(*student1, "Jane Doe");

cout << "\nAfter update:\n";

student1->displayInfo();

// Clean up dynamic memory

delete student1;

} catch (const std::exception &e)

cerr << "An error occurred: " << e.what() << endl;

return 0;

OUTPUT:

You might also like