Home > Back-end >  C program, the constructor
C program, the constructor

Time:09-20

[a] project to design a student class, the students the basic information of the student id, name, age, gender and class position (monitor, learning committee member, competitive person, and students), etc., by increasing the constructor, enables object when defining the data member is initialized, among them, the gender of the default value is "male", class position is "student" by default, specific requirements are as follows:
(1) design the constructor, complete the initialization of object data members, among them, the data member is initialized using member initialization list,
(2) to design a function points, student's class position for bonus points, if you don't points is normal, the monitor add 5 points, study committee and three points, competitive person add 2 points,
(3) the design output function, the basic information of the output, and the student should add score,
Please, no, is there any bosses give a help,

CodePudding user response:

It's too late to give you case tomorrow

CodePudding user response:

 # include & lt; Iostream> 
#include
using namespace std;

The class Student
{
Public:
//id: student id
//sName: name
//iAge: age
//sXb: gender, M: male, female F:
//iZw: position, 0: students, 1 month, 2: learning committee member, 3: competitive person
Student (string id, string sName, int iAge, string sXb="M", int iZhiwu=0).
Void the print ();
Private:
Int getScore ();//receive points, without considering multiple position

String m_sId;
String m_sName;
Int m_iAge;
String m_sXb;
Int m_iZw;
};

Student: : Student (string id, string sName, int iAge, string sXb, int iZw) :
M_sId (id), m_sName (sName), m_iAge (iAge), m_sXb (sXb), m_iZw (iZw)
{
}

Void Student: : print ()
{
Cout & lt; & lt; "ID:" & lt; & lt; M_sId & lt; & lt; "Name:" & lt; & lt; M_sName & lt; & lt; "The Age:" & lt; & lt; M_iAge & lt; & lt; "Xb:" & lt; & lt; M_sXb & lt; & lt; "IZw:" & lt; & lt; M_iZw & lt; & lt; "Score:" & lt; & lt; GetScore () & lt; & lt; endl;
}

Int Student: : getScore ()
{
Static int scores []=,5,3,2 {0};//score table, and position the serial number corresponding to the
Return scores [m_iZw];
}

Int main (int arg c, char * argv [])
{
//example: female, learning committee member
Student a (" 001 ", "Lili", 15, "F", 2);
Amy polumbo rint ();
return 0;
}

CodePudding user response:

refer to the second floor SeRapHiw response:
 # include & lt; Iostream> 
#include
using namespace std;

The class Student
{
Public:
//id: student id
//sName: name
//iAge: age
//sXb: gender, M: male, female F:
//iZw: position, 0: students, 1 month, 2: learning committee member, 3: competitive person
Student (string id, string sName, int iAge, string sXb="M", int iZhiwu=0).
Void the print ();
Private:
Int getScore ();//receive points, without considering multiple position

String m_sId;
String m_sName;
Int m_iAge;
String m_sXb;
Int m_iZw;
};

Student: : Student (string id, string sName, int iAge, string sXb, int iZw) :
M_sId (id), m_sName (sName), m_iAge (iAge), m_sXb (sXb), m_iZw (iZw)
{
}

Void Student: : print ()
{
Cout & lt; & lt; "ID:" & lt; & lt; M_sId & lt; & lt; "Name:" & lt; & lt; M_sName & lt; & lt; "The Age:" & lt; & lt; M_iAge & lt; & lt; "Xb:" & lt; & lt; M_sXb & lt; & lt; "IZw:" & lt; & lt; M_iZw & lt; & lt; "Score:" & lt; & lt; GetScore () & lt; & lt; endl;
}

Int Student: : getScore ()
{
Static int scores []=,5,3,2 {0};//score table, and position the serial number corresponding to the
Return scores [m_iZw];
}

Int main (int arg c, char * argv [])
{
//example: female, learning committee member
Student a (" 001 ", "Lili", 15, "F", 2);
Amy polumbo rint ();
return 0;
}

Thank you very much bosses

CodePudding user response:

I think when you initialize the building Lord, want to use reference, so that more efficient, especially for the long string, or you not copy,

CodePudding user response:

I go back to the 2nd floor, ha ha the building Lord!

CodePudding user response:

reference 1/f, Simple, Soft reply:
it is too late, tomorrow to give you example
the eldest brother don't need so tired!

CodePudding user response:

Really touched I was a freshman, the final report, really touched,
  • Related