question archive Write a C++ program that defines a class called Student and private fields are “studentId” type interget, ”studentName” of type string and ”cgpa” type of double

Write a C++ program that defines a class called Student and private fields are “studentId” type interget, ”studentName” of type string and ”cgpa” type of double

Subject:Computer SciencePrice:2.87 Bought7

Write a C++ program that defines a class called Student and private fields are “studentId” type interget, ”studentName” of type string and ”cgpa” type of double. The class also has all type of constructors (default, parameterized and copy) and display function to prints the information

Also, provide how the program is typed in the minimum of 5 sentences

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Answer:

Here is the Source Code

#include <iostream>


class Student
{
private:
int studentID;
char studentName[100];
double cgpa;
  
public:
  
Student() // Default Constructor
{
std::cout<<"We are in default Constructor"<<std::endl;
}
  
Student(int a, char *b, double c) // paramatrized constructor
{
std::cout<<"We are in Paramatrized Constructor"<<std::endl;
studentID = a;
int i ;
for(i=0;b[i] != '\0';i++)
{
  
studentName[i] = b[i];
}
cgpa = c;
}
  
  
Student(const Student &ab ) // copy constructor
{
  
std::cout<<"We are in Copy Constructor"<<std::endl;
studentID = ab.studentID;
int i ;
for(i=0;ab.studentName[i] != '\0';i++)
{
  
studentName[i] = ab.studentName[i];
}
  
cgpa = ab.cgpa;
  
}
  
void display() // class method to display values
{
  
  
std:: cout << "Student Id is " <<studentID<<std::endl;
std::cout << "Student Name is "<<studentName<<std::endl;
std::cout << " Student cgpa is " << cgpa<<std::endl;
}
  
  
};
int main() {
Student def = Student();//this invokes default constructor
  
Student a = Student(10,"Ram",8.76); // Invoking the paramatrized constructor
a.display();
  
Student b = Student(a);// invoking the copy constructor
  
b.display();

return 0;
}

Here is the code snippet and output:

please use this google drive link to download the answer file.

https://drive.google.com/file/d/1BymaSthaFIp68vfk6ClxzT70W-P4fTlQ/view?usp=sharing

note: if you have any trouble in viewing/downloading the answer from the given link, please use this below guide to understand the whole process.

https://helpinhomework.org/blog/how-to-obtain-answer-through-google-drive-link