Practical 5
Practical 5
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--;
}
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
return 0;
}