Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote