作业.01

一.代码:

  

#include<stdio.h>
#include<stdlib.h>
#include<string>
struct student {
 char name[10];
 int num;
 char sex[10];
 char cla[10];
 double score;
}stu[10];
int main()
{
 system("color FC");
 printf("**************\n");
 printf("  欢迎使用  \n");
 printf(" 按0进入系统 \n");
 printf("**************\n");
 int n;
 scanf("%d", &n);
 system("cls");
 if (n == 0) {
  FILE* fp;
  int i;
  for (i = 0; i < 10; i++) {
   printf("请输入名字:");
   scanf("%s", &stu[i].name);
   strcat(stu[i].name, ".txt");
   fp = fopen(stu[i].name, "w+");
   if (fp) {
    printf("请输入 学号 性别 班级 成绩\n");
    scanf("%d %s %s %lf", &stu[i].num, &stu[i].sex, &stu[i].cla, &stu[i].score);
    fprintf(fp, "%d %s %s %.2f", stu[i].num, stu[i].sex, stu[i].cla, stu[i].score);
   }
   else {
    printf("Error!");
    exit(0);
   }
   if (fclose(fp)) {
    printf("Can not close the file!\n");
    exit(0);
   }
  }
 }
 else {
  printf("Error!");
  exit(0);
 }
 system("pause");
 return 0;
}

二.效果:

    

 

    

 

     

 

 

 

三.system命令:

  system("cls"):清屏功能

  system("pause"):暂停功能

  system("color F1"):F是背景色,1是字体色。

 

  0:黑色  1:蓝色  2:绿色  3:浅绿色  4:红色  5 = 紫色  6 = 黄色  7 = 白色  8:灰色  9:淡蓝色

 

 

 

  A:淡绿色  B:淡浅绿色  C:淡红色  D:淡紫色  E:淡黄色  F:亮白色

posted @ 2019-12-17 20:39  月光寰宇(白靖)  阅读(326)  评论(0编辑  收藏  举报