gpt4 book ai didi

c++ - 插入学生的姓名及其 ID 并向他们展示

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:15:14 24 4
gpt4 key购买 nike

<分区>

这是我的C++代码

学生.h

#include <string>

using namespace std;

class student
{
public:
void setname ();
string getname ();

void setstudentid ();
int getstudentid ();

student ();


private:
string name;
int studentid;

};

学生.cpp

#include "student.h"
#include <iostream>

using namespace std;

student::student ()
{
setname ();

setstudentid ();

cout << "Student's Name: " << getname () << endl;
cout << "Student's ID: " << getstudentid () << endl;
}

void student::setname ()
{
string x;

cout << "Enter student's name: ";
getline (cin , x);


name = x;
}

string student::getname ()
{
return name;
}

void student::setstudentid ()
{
int x;

cout << "Enter student's code: ";
cin >> x;

studentid = x;
}

int student::getstudentid ()
{
return studentid;
}

主要.cpp

#include <iostream>
#include <string>
#include "student.h"

using namespace std;

int main ()
{
int a;

cout << "1- stundent's info" << endl
<< "2- list of courses" << endl
<< "3- PickUp a course" << endl
<< "Please enter an option: ";
cin >> a;

if (a == 1)
{
student x;
}
}

问题如下图:

enter image description here

如何使用初始化变量分别打印它们?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com