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

Constructor Program

The document contains two C++ programming tasks: one for creating a Student Admission System with a class that uses a default constructor to assign roll number and department, and another for an Employee Payroll System that uses a parameterized constructor to initialize employee details. Each task includes a class definition, constructor implementation, and a display function to show the details. Example code snippets for both tasks are provided.

Uploaded by

mathalai raj
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)
2 views3 pages

Constructor Program

The document contains two C++ programming tasks: one for creating a Student Admission System with a class that uses a default constructor to assign roll number and department, and another for an Employee Payroll System that uses a parameterized constructor to initialize employee details. Each task includes a class definition, constructor implementation, and a display function to show the details. Example code snippets for both tasks are provided.

Uploaded by

mathalai raj
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

Question 1.

A college wants to develop a simple Student Admission System. When a new student record
is created, the system should automatically assign default values for the student’s roll
number and department.

Write a C++ program that:

1. Uses a class Student with data members: rollNo, department.

2. Uses a default constructor to assign default values.

3. Displays the student details using a member function.

Question 2.

An organization is developing an Employee Payroll System. Each employee’s details such as


employee ID and basic salary should be provided at the time of object creation.

Write a C++ program that:

1. Uses a class Employee with data members: empId, basicSalary.

2. Uses a parameterized constructor to initialize values at runtime.

3. Displays the employee payroll details.


#include <iostream>
using namespace std;

class Student {
int rollNo;
string department;

public:
// Default Constructor
Student() {
rollNo = 1001;
department = "Computer Science";
}

void display() {
cout << "Roll Number : " << rollNo << endl;
cout << "Department : " << department << endl;
}
};

int main() {
Student s; // Default constructor is invoked automatically
[Link]();
return 0;
}
#include <iostream>
using namespace std;

class Employee {
int empId;
float basicSalary;

public:
// Parameterized Constructor
Employee(int id, float salary) {
empId = id;
basicSalary = salary;
}

void display() {
cout << "Employee ID : " << empId << endl;
cout << "Basic Salary : " << basicSalary << endl;
}
};

int main() {
Employee e(201, 30000); // Values passed at object creation
[Link]();
return 0;
}

You might also like