/*用结构体变量指针作为实参输出学生学号 姓名 三门课成绩 */
#include<iostream>
using namespace std;
struct student
{
int num;
char name[20];
float score1;
float score2;
float score3;
};
void print(student *p)
{
cout<<"Num"<<"\tName"<<"\t\tScore1"<<"\tScore2"<<"\tScore3"<<endl;
cout<<p->num<<"\t"<<p->name<<"\t\t"<<p->score1<<"\t"<<p->score2<<"\t"<<p->score3<<endl;
}
int main()
{
student student1={1001,"Li ling",77,83,92};
print(&student1);
return 0;
}
/*main函数中输入数据,print函数输出学生学号 姓名 三门课成绩 */
#include<iostream>
using namespace std;
struct student
{
int num;
char name[20];
float score1;
float score2;
float score3;
};
void print(student student1)
{
cout<<"Num"<<"\tName"<<"\t\tScore1"<<"\tScore2"<<"\tScore3"<<endl;
cout<<student1.num<<"\t"<<student1.name<<"\t\t"<<student1.score1<<"\t"<<student1.score2<<"\t"<<student1.score3<<endl;
}
int main()
{
student student1={1001,"Li ling",77,83,92};
print(student1);
return 0;
}
/*用共用体的方式将一个整数输出对应的ascII码字符 */
#include<iostream>
using namespace std;
union st
{
int a;
char b[2];
}change;
int main()
{
cout<<"请输入一个整数,若大于127则退出"<<endl;
while(1)
{
cin>>change.a;
if(change.a>127)
break;
cout<<change.a<<"对应的字符为:"<<change.b<<endl;
}
return 0;
}
/*找出基本工资和职务工资最少的员工,并将其所有资料输出 */
#include<iostream>
using namespace std;
struct staff
{
int num;
char name[20];
float basewage;
float postwage;
};
int main()
{
staff stu[4]={{1001,"Zhang zi",700,800},{1002,"Zhu hai",800,1000}
,{1003,"Li li",1000,1200},{1004,"Ma hua",700,900}}; /*10个员工有点多,这里只做4个作为示范,算法一样*/
staff temp;
for(int i=0;i<4;i++)
for(int j=0;j<=5-i;j++)
if((stu[j].basewage+stu[j].postwage)<(stu[j+1].basewage+stu[j+1].postwage))
{
temp=stu[j+1];
}
cout<<"Num\t"<<"Name\t\t"<<"basewage\t"<<"postwage"<<endl;
cout<<temp.num<<"\t"<<temp.name<<"\t\t"<<temp.basewage<<"\t\t"<<temp.postwage<<endl;
return 0;
}
/*输入年月日,计算该日是这年的第几日*/
#include<iostream>
using namespace std;
int main()
{
int year,month,day,n;
cout<<"请输入年月日:"<<endl;
cin>>year>>month>>day;
switch(month)
{
case 1:n=day;break;
case 2:n=31+day;break;
case 3:n=31+28+day;break;
case 4:n=31+28+31+day;break;
case 5:n=31+28+31+30+day;break;
case 6:n=31+28+31+30+31+day;break;
case 7:n=31+28+31+30+31+30+day;break;
case 8:n=31+28+31+30+31+30+31+day;break;
case 9:n=31+28+31+30+31+30+31+31+day;break;
case 10:n=31+28+31+30+31+30+31+31+30+day;break;
case 11:n=31+28+31+30+31+30+31+31+30+31+day;break;
case 12:n=31+28+31+30+31+30+31+31+30+31+30+day;break;
}
if(month>=2&&((year%400==0)||((year%4==0)&&(year!=0))))
n=n+1;
cout<<year<<"-"<<month<<"-"<<day<<"是"<<year<<"年的第"<<n<<"天"<<endl;
return 0;
}