Among them, student id, name is public property, the result is a private property,
In different ways to student's student id, name, performance of assignment,
Output is then called a member function display student's student id, name and grade information, */
Excuse me, if you want to give the following code under no arguments constructor name assignment, statements should be how to write, before I write the name={' no ', 'a', 'f'}; The compiler error.
And the main function of Student s1, s2 (" 002 ", "zhang", 18); This statement, the compiler hint "no constructor to match the parameter list" is what reason!
#include
using namespace std;
The class Student {
Public:
Char ID [20];
char name[10];
//a no-parameter constructor
Student (a)
{
Cout<" Default: "& lt;
//a parameter constructor
Student (const char a, b const char, int c)
{
Cout<" Zhang SAN was born!"
The name [10]=b;
Score=c;
Void the display ();
}
//destructors
To the Student ()
{
Cout
Void the display () {
Cout<" Student number: "& lt;
Private:
int score;
};
Int main ()
{
Student s1, s2 (" 002 ", "zhang", 18);
S1. The display ();
S2. The display ();
return 0;
}
CodePudding user response:
Thanks for invitation, written examples can participate,CodePudding user response:
Here only talk about the mistake I see ah, don't look to the rest of the code, personally think that the error was caused by your lack of basic common sense, had better look for a c/c + + primer book system to learnStudent (const char a, b const char, int) c//here a, b statement for char is wrong, should be a const char *
{
Cout<" Zhang SAN was born!"
The name [10]=b;//same as above
this sentenceScore=c;
Void the display ();
}
CodePudding user response:
class Student {
Public:
Char ID [20]={0};
Char name [10]={0};
//a no-parameter constructor
Student (a)
{
Strncpy (name, "John doe", 10);
Cout & lt; <"The default:" & lt;}
//a parameter constructor
Student (const char * a, const char * b, int c)
{
Cout & lt; <"Zhang SAN was born!"Strncpy (ID, a, 20);
Strncpy (name, b, 10);
Score=c;
Void the display ();
}
//destructors
To the Student ()
{
Cout & lt;}
Void the display () {
Cout & lt; <"Student id:" & lt;Cout & lt; <"Name:" & lt; Cout & lt; <"Record:" & lt; }
Private:
Int score=0;
};