Objective
The objective of this assignment is to provide hands on experience of using
Classes and Objects
Dynamic Memory Allocation in C/C++
Friend Functions
Program
Write a C++ program that contains a class named Student having following data members:

1. stdId
2. stdName
3. stdAge
4. stdProgram
5. noOfSubjects.

The class Student must have

• A default constructor which must initialize all the data members to their meaningful values.
• A parameterized constructor which takes values for all the data members as parameters and assign them to their respective fields in class.
• A destructor with no implementation.
• Setter member functions to set all data members (stdId, stdName, stdAge, stdProgram, and noOfSubjects).
• Getter member functions to get all data members (stdId, stdName, stdAge, stdProgram and noOfSubjects).
• Display() member function to display the data for each student.
• Friend function of class that receives an object of type “Student”

Display() member function takes no parameters and displays all the student‘s information on the output screen.

Friend function of class receives an object of type “Student” and determines whether a student has registered in more than five subjects or not.
If a student registers in more than five subjects then it should display a message that “Student has registered in more than 5 subjects” and if a student does not register in more than 5 subjects then it should display a message that “Student has not registered in more than 5 subjects”.

In main function of the program

• Dynamically allocate memory for two objects of type “Student”.
• Prompt the user to enter data for each student and store into an object of type “Student”.
• After setting data for each student, display the data for each student by calling display method.
• Determines whether a student has registered more than five subjects or not by calling friend function.
• Deallocate memory that was allocated to objects


Sample Output of Program:


Please enter data for student 1

Student ID: std01
Student Name: Sadia
Student Age: 18
Student Program: BCS
Number of Subjects: 3

Please enter data for student 2

Student ID: std02
Student Name: Sidra
Student Age: 17
Student Program: BBA
Number of Subjects: 6

Displaying records for registered students

Record for Student 1

Student ID: std01
Student Name: Sadia
Student Age: 18
Student Program: BCS
Number of Subjects: 3


Record for student 2

Student ID: std02
Student Name: Sidra
Student Age: 17
Student Program: BBA
Number of Subjects: 6

Student 1 has not registered in more than 5 subjects
Student 2 has registered in more than 5 subjects

Good day to you. Please post youe question in the C++ section of this forum along with your code so it can be reviewed....sorry....no free answers here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.