zoukankan      html  css  js  c++  java
  • 为了防止头文件被重复引用

    为了防止头文件被重复引用,应当用 ifndef/define/endif 结构产生预处 理块。

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 
     5 using namespace std;
     6 //定义公共结构类型
     7 struct student {
     8        int  num;
     9        char  name[10];
    10        float maths;
    11        float physics;
    12        float chemistry;
    13        double  total;
    14 };
    15  
    16 //定义结构输入函数
    17 input_Rec(struct student *p)   //参数为student类型的结构指针变量
    18 {
    19     cin>>p->num;
    20     cin>>p->name;
    21     cin>>p->maths;
    22     cin>>p->physics;
    23     cin>>p->chemistry;
    24 }
    25 
    26 //定义结构数据交换函数
    27 swap_Rec(struct student *p1,struct student *p2)
    28 {
    29     struct student x;
    30 
    31     //交换两个记录的数据
    32     x=*p1;
    33     *p1=*p2;
    34     *p2=x;
    35 }
    36 
    37 //输出结构的值
    38 put_Rec(struct student *p)
    39 {
    40     cout<<p->num<<'	';
    41     cout<<p->name<<'	';
    42     cout<<p->maths<<'	';
    43     cout<<p->physics<<'	';
    44     cout<<p->chemistry<<'	';
    45     cout<<p->total<<endl;
    46 }
    47 
    48 
    49 
    50 int main(int argc, char** argv) {
    51     
    52      int i,j;
    53     // 声明结构指针变量和结构数组 
    54     struct student *p1,a[3];  
    55 
    56     //输入3个学生的数据并计算总成绩
    57     cout<<"num	name	maths	physics	chemistry"<<endl;
    58     for (p1=a;p1<=a+2;p1++)  {
    59          input_Rec(p1);
    60          p1->total=p1->maths+p1->physics+p1->chemistry;
    61     }
    62 
    63     //对3个学生的数据排序
    64     for (i=0;i<=2;i++)  
    65          for (j=i+1;j<=2;j++)
    66              if (a[i].total<a[j].total)
    67                  swap_Rec(&a[i],&a[j]);   //交换两个结构变量中的数据
    68      cout<<"-------------------"<<endl;      //输出一分界线
    69 
    70      //输出排序后的结构数组
    71     cout<<"num	name	maths	physics	chemistry	total"<<endl;
    72     for (p1=a;p1<=a+2;p1++)
    73           put_Rec(p1);
    74     return 0;
    75 }
  • 相关阅读:
    [Err] 1168
    SpringAOP的运用方式——注解方式和XML配置方式
    展开运算符的理解
    find indexof findindex includes 的区别
    关于MVC MVVM的理解
    sync修饰符
    vue导航守卫
    输入网址到页面显示 经历了什么(转载)
    vue中侦听器的使用
    函数声明的三种方式
  • 原文地址:https://www.cnblogs.com/borter/p/9412880.html
Copyright © 2011-2022 走看看