
class student
{
public:
string name;
char sex;
int num;
double sc;
}
student xuesheng[];
#include "stdafxh"
#include <iostream>
using namespace std;
#define GENDER_MALE 1//定义1为性别男
#define GENDER_FEMALE 2//定义2为性别女
typedef struct tagTUDENTINFO{//定义结构体,储存学生信息
char name[10];//姓名
int gender;//性别
int studentNumber;//学号
void ShowNameAndGender();//显示姓名和性别
}StudentInfo;
void StudentInfo::ShowNameAndGender()
{
cout<<"姓名:"<<this->name<<endl;
if(GENDER_MALE == this->gender){
cout<<"性别:男"<<endl;
}
else{
cout<<"性别:女"<<endl;
}
}
#define STUDENTS_NUMBER 3//学生人数,为了方便演示,设置为3
int _tmain(int argc, _TCHAR argv[])
{
StudentInfo pStudentInfo = new StudentInfo[STUDENTS_NUMBER];//为学生信息分配存储空间
memset(pStudentInfo[0]name, 0, 10);
memcpy(pStudentInfo[0]name, "张三", sizeof(char)strlen("张三"));
pStudentInfo[0]gender = GENDER_FEMALE;
pStudentInfo[0]studentNumber = 101;
memset(pStudentInfo[1]name, 0, 10);
memcpy(pStudentInfo[1]name, "李四", sizeof(char)strlen("李四"));
pStudentInfo[1]gender = GENDER_MALE;
pStudentInfo[1]studentNumber = 102;
memset(pStudentInfo[2]name, 0, 10);
memcpy(pStudentInfo[2]name, "王五", sizeof(char)strlen("王五"));
pStudentInfo[2]gender = GENDER_MALE;
pStudentInfo[2]studentNumber = 103;
cout<<"请输入学号:"<<endl;
int num;
cin>>num;
//搜索记录,查找学号对应的记录
bool find = false;
for(int i=0;i<STUDENTS_NUMBER;i++){
if(pStudentInfo[i]studentNumber == num){
pStudentInfo[i]ShowNameAndGender();
find = true;
}
}
//若没有找到
if(!find){
cout<<"学号输入有误!"<<endl;
}
system("pause");
delete [] pStudentInfo;//内存回收
pStudentInfo = NULL;
return 0;
}
#include <stdioh>
int main(void)
{
char a[5]={0};
scanf("%s",a);
if(!strcmp(a,"男")) printf("我是男人\n");
else if(!strcmp(a,"女")) printf("我是女人\n");
return 0;
}
你看看行不行,
string sex = stringempty;
取出的值赋给sex;然后:
radioButton1Checked = sex = "男" true : false;
radioButton2Checked = sex = "女" true : false;
#include <iostream>
using namespace std;
int main()
{
int sex ;
cout<<"1M 2F"<<endl;
cin>>sex;
if(sex ==1)cout<<"M"<<endl;
if(sex == 2)cout<<"F"<<endl;
return 0;
}
以上就是关于用C++中类的程序编写学生的姓、性别、学号和成绩全部的内容,包括:用C++中类的程序编写学生的姓、性别、学号和成绩、用c++编写简单的程序,已经储存了全班44个同学的姓名,性别,学号。输入学号就可以输出这个人的名和性别。、怎么用C语言程序写一个辨别男女的程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)