C++程序 设计一个类类型student 实现数据输入输出,学生信息包括姓名,性别和年龄
展开全部
#include<iostream>
#include<string>
using namespace std;
class student
{
int n;
int a[100];
char c[100];
string s[100];
public:
student()
{
}
void set()
{
cout<<"请输入学生个数:";
cin>>n;
}
void input()
{
for(int i=0;i<n;i++)
{
cout<<"请输入第"<<i+1<<"个学生的姓名:";
cin>>s[i];
cout<<"请输入第"<<i+1<<"个学生的性别(f:女/m:男):";
cin>>c[i];
cout<<"请输入第"<<i+1<<"个学生的年龄:";
cin>>a[i];
}
}
void output()
{
for(int i=0;i<n;i++)
{
cout<<i+1<<"\t\t"<<s[i]<<"\t\t"<<c[i]<<"\t\t"<<a[i]<<"\t\t"<<endl;
}
}
~student(){}
};
void main()
{
char flag='Y';
student st;
st.set();
st.input();
cout<<"是否需要输出信息?(Y/N):";
cin>>flag;
if(flag=='Y'||flag=='y')
{
cout<<"序号\t\t"<<"姓名\t\t"<<"性别\t\t"<<"年龄\t\t"<<endl;
st.output();
}
}
阿门 经过了检验
#include<string>
using namespace std;
class student
{
int n;
int a[100];
char c[100];
string s[100];
public:
student()
{
}
void set()
{
cout<<"请输入学生个数:";
cin>>n;
}
void input()
{
for(int i=0;i<n;i++)
{
cout<<"请输入第"<<i+1<<"个学生的姓名:";
cin>>s[i];
cout<<"请输入第"<<i+1<<"个学生的性别(f:女/m:男):";
cin>>c[i];
cout<<"请输入第"<<i+1<<"个学生的年龄:";
cin>>a[i];
}
}
void output()
{
for(int i=0;i<n;i++)
{
cout<<i+1<<"\t\t"<<s[i]<<"\t\t"<<c[i]<<"\t\t"<<a[i]<<"\t\t"<<endl;
}
}
~student(){}
};
void main()
{
char flag='Y';
student st;
st.set();
st.input();
cout<<"是否需要输出信息?(Y/N):";
cin>>flag;
if(flag=='Y'||flag=='y')
{
cout<<"序号\t\t"<<"姓名\t\t"<<"性别\t\t"<<"年龄\t\t"<<endl;
st.output();
}
}
阿门 经过了检验
展开全部
#include <iostream>
#include <string>
using namespace std;
class Student
{
private:
string name;
string sex;
int age;
public:
void setMessage(string n, string s, int a);
void getMessage();
};
void Student::setMessage(string n, string s, int a)
{
name = n;
sex = s;
age = a;
}
void Student::getMessage()
{
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
cout << "age:" << age << endl;
}
int main()
{
Student s;
s.setMessage("张三", "男", 22);
s.getMessage();
return 0;
}
#include <string>
using namespace std;
class Student
{
private:
string name;
string sex;
int age;
public:
void setMessage(string n, string s, int a);
void getMessage();
};
void Student::setMessage(string n, string s, int a)
{
name = n;
sex = s;
age = a;
}
void Student::getMessage()
{
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
cout << "age:" << age << endl;
}
int main()
{
Student s;
s.setMessage("张三", "男", 22);
s.getMessage();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询