因此,我将这段代码编写为作业的一部分,就像这样,我们仍在学习C语言,但我无法对此进行更正。我们必须编写代码来编写函数,以打印出特定年份加入的所有学生的姓名。
它将运行代码直到switch case
,但以后将无法使用。
#include<stdio.h>
struct stdnt
{
char stName[100];
char stRNo[100];
char Dept[50];
char crse[50];
int YoJ[4];
}s[2];
void stYr(p)
{
printf("Student Name = %s\t",s[p].stName);
}
void stRnm(q)// q Rnm
{
int i;
for(i=0;i<=1;i++)
{if(q == s[i].stRNo)
{
printf("Student Name = %s\t",s[i].stName);
printf("Student Year of Joining = %d\t",s[i].YoJ);
printf("Student Department = %s\t",s[i].Dept);
printf("Student Course = %s\n",s[i].crse);
}
}
}
int main()
{
int i;
int year;
int Rnm;
int ch;
printf("Please Enter the details of 2 Students.\n");
for(i=0;i<=1;i++)
{
printf("Enter Name of Student %d:\n",i+1);
scanf("%s",s[i].stName);
printf("Enter Department of Student %d:\n",s[i].Dept);
printf("Enter Year of Joining of Student %d:\n",i+1);
scanf("%d",s[i].YoJ);
printf("Enter Roll Number of Student %d:\n",s[i].stRNo);
printf("Enter Course of Student %d:\n",s[i].crse);
}
printf("Enter 1 to Print the List of Student using Year.\nEnter 2 to Search the details of student using Roll no.\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter the Year:\n");
scanf("%d",&year);
for(i=0;i<=1;i++)
{
if(year == s[i].YoJ)
{
stYr(i);
}
}
break;
case 2:
printf("Enter the roll number you want to search:\n");
scanf("%d",&Rnm);
stRnm(Rnm);
break;
}
return 0;
}
问题是
创建一个结构以指定以下学生的数据:卷号,姓名,系,课程,入学年份。
假设学生人数不超过450名(我尝试先编写2个代码,那么一旦工作,便可以使用450个代码)
也是`
- 编写一个函数以打印特定年份加入的所有学生的姓名。
- 编写另一个功能以打印输入了卷号的学生的数据
制作开关盒。
我得到的输出:
请输入2位学生的详细信息。
输入学生1的姓名:
凯蒂尔
输入部门:
机械
输入加入年份:
2019
输入卷号:
1
进入课程:
C
输入学生2的姓名:
普兰尼
输入部门:
机械
输入加入年份:
2019
输入卷号:
2
进入课程:
C
输入1以使用年份打印学生列表
输入2以使用卷号打印学生的详细信息
1
输入年份:
2019
进程返回0 执行时间30.600s
按任意键继续。
预期输出:
在切换案例后输入Year之后,我希望调用函数`stYr并打印以该Year为加入年的学生的列表
类似地,如果输入了卷号,我希望打印该学生的详细信息。