Which of the following class definitions is correct in C++? (i) class Student {
ID: 3653279 • Letter: W
Question
Which of the following class definitions is correct in C++?
(i)
class Student
{
public:
void Student();
void Student (string s, double g, int i);
void set(string s, double g, int i);
void print();
private:
string name;
double gpa;
int id;
};
(ii)
class Student
{
public:
Student();
Student (string s, double g, int i);
void set(string s, double g, int i);
void print();
private:
string name;
double gpa;
int id;
private:
string name;
double gpa;
int id;
};
A. Only i
B. Only ii
C. Both i and ii
D. none of these..
Please explain!!
Explanation / Answer
please rate - thanks
Which of the following class definitions is correct in C++?
(i)
class Student
{
public:
void Student();
void Student (string s, double g, int i);
void set(string s, double g, int i);
void print();
private:
string name;
double gpa;
int id;
};
(ii)
class Student
{
public:
Student();
Student (string s, double g, int i);
void set(string s, double g, int i);
void print();
private:
string name;
double gpa;
int id;
private:
string name;
double gpa;
int id;
};
A. Only i
B. Only ii
C. Both i and ii
D. none of these..
a function has to return a type, not a constructor
so in this one Student(); is supposed to be the default constructor. Student(string s,double g, int i); is supposed to be a constructor, but because of the void they are incorrect form
class Student
{
public:
void Student();
void Student (string s, double g, int i);
void set(string s, double g, int i);
void print();
private:
string name;
double gpa;
int id;
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.