标签:style blog color io for div ar 管理
Home Assignment:-
* Create a menu driven application where you will have 2 types of users to login in Admin and Student
*写一个面板程序,要求用户可以Admin和Student两种用户身份进入系统
*Admin下你需要用以下结构体登记学生信息
The Admin will register the student along with all his detail as per the below strucutre
struct Student{
int rollno;
char name[20];
char address[30];
char username[10]
char password[10]
float EnglishMarks;
float MathsMarks
float ScienceMarks
float total
float average;
char grade.
}
*至少登记5位学生的信息,并且所有的学生信息都得储存在数组中
Register atleast 5 students and all the students will be stored into and array of students :-
e.g :- struct student studlist[10];
*关于总成绩、平均值。
calculate the total, average
Grade will be calculated as per following:-
*成绩评定标准如下
if average is above 90:- ‘A‘
75-90 -‘B‘
50-74 -‘C‘
less than 50 ‘F‘
Sample Output:-
Main Menu:-
1.Login as Administrator
2.Login as Student
Enter Your Choice:-1
Enter Username:-admin
Enter Password:-admin
Welcome Admin
Admin Menu
1. Register Student
2.View Students
3. Exit
Enter Choice:- 1
Enter Details of Student
Rollno:-101
Name :-Scott
Address :- Wuxi
username:- scott
password:- scott
English Marks:- 60
Maths Marks :- 78
Science Marks:- 90
Student Registered Successfully !!!
Admin Menu
1. Register Student
2.View Students
3. Exit
Enter Choice:- 3
Main Menu:-
1.Login as Administrator
2.Login as Student
Enter Your Choice:-2
Enter Username:-scott
Enter Password:-scott
Welcome Student
Student Menu
1. View Marks
2. Exit
Enter Choice:- 1
English MAths Science Total AVERAGE Grade
60 78 90 228 76 B
#include<stdio.h> #include<string.h> #include<stdlib.h> void mainMenu(); void admin(); void adminMenu(); void student(); void studentMenu(); void viewStudents(); void viewMarks(); void registerStudent(); void exit(); int isEqual(char a[],char b[]); struct Student{ int rollno; char name[20]; char address[30]; char username[10]; char password[10]; float EnglishMarks; float MathsMarks; float ScienceMarks; float total; float average; char grade; }studlist[10]; int x=-1; // student index is find,-1 means not find int index=0; // register numbers of students //主方法 void main(){ int choice; char username[10]="admin"; //admin username char password[10]="admin"; //admin password while(1) { mainMenu(); scanf("%d",&choice); getchar(); //防止输入字符陷入死循环 switch(choice) { case 1: char AName[10], AWord[10]; printf("Enter Username:"); scanf("%s",&AName); printf("Enter Password:"); scanf("%s",&AWord); if(isEqual(AName,username) && isEqual(AWord,password)) admin(); else { printf("The username or password is not right\n"); main(); } break; case 2: int i; char uName[10], pWord[10]; printf("Enter Username:"); scanf("%s",&uName); printf("Enter Password:"); scanf("%s",&pWord); // printf("index=%d\n",index); for(i=0;i<index;i++) { // printf("isEqualU()=%d,isEqualP()=%d ,%d\n ",isEqual(uName,studlist[i].username) ,isEqual(pWord,studlist[i].password),isEqual(uName,studlist[i].username) && isEqual(pWord,studlist[i].password)); if(isEqual(uName,studlist[i].username) && isEqual(pWord,studlist[i].password)) { x=i; //将下标i赋值给全局变量x; student(); } } if(x==-1) { printf("The username or password is not right\n"); } break; default:printf("You enter the wrong choice!\n"); } } } //主菜单 void mainMenu() { printf("---------------------------------------------\n"); printf("------ Welcome to use StumentSystems! ------\n"); printf("------ 1.Login as Administrator ------\n"); printf("------ 2.Login as Student ------\n"); printf("---------------------------------------------\n"); printf("Enter Your Choice:"); } //管理员菜单 void adminMenu(){ int choice=-1; printf("---------------------------------------------\n"); printf("------ 1. Register Student ------\n"); printf("------ 2.View Students ------\n"); printf("------ 3. Exit ------\n"); printf("---------------------------------------------\n"); printf("Enter Your Choice:"); } //学生菜单 void studentMenu() { printf("---------------------------------------------\n"); printf("------ 1. View Marks ------\n"); printf("------ 2. Exit ------\n"); printf("---------------------------------------------\n"); printf("Enter Your Choice:"); } //管理员 void admin(){ int choice=-1; while(choice!=3) { adminMenu(); scanf("%d",&choice); switch(choice) { case 1:registerStudent();break; case 2:viewStudents();break; case 3:exit();break; default:printf("You enter the wrong choice!\n"); } } } //学生 void student(){ int choice=-1; while(choice!=2) { studentMenu(); scanf("%d",&choice); switch(choice) { case 1:viewMarks();break; case 2:exit();break; default:printf("You enter the wrong choice!\n"); } } } //登记学生信息 void registerStudent() { printf("Enter Details of Student\n"); printf("Rollno:"); scanf("%d",&studlist[index].rollno); printf("Name:"); scanf("%s",studlist[index].name); printf("Address:"); scanf("%s",studlist[index].address ); printf("Username:"); scanf("%s",studlist[index].username); printf("Password:"); scanf("%s",studlist[index].password); printf("English Marks:"); scanf("%f",&studlist[index].EnglishMarks); printf("Maths Marks:"); scanf("%f",&studlist[index].MathsMarks); printf("Science Marks:"); scanf("%f",&studlist[index].ScienceMarks); //总分 平均分 和 等级 studlist[index].total=studlist[index].EnglishMarks+studlist[index].MathsMarks+studlist[index].ScienceMarks; studlist[index].average=(studlist[index].EnglishMarks+studlist[index].MathsMarks+studlist[index].ScienceMarks)/3; if(studlist[index].average>=90) { studlist[index].grade=‘A‘; } else if(studlist[index].average<90&&(studlist[index].average>=75)) { studlist[index].grade=‘B‘; } else if(studlist[index].average<75&&(studlist[index].average>=50)) { studlist[index].grade=‘C‘; } else { studlist[index].grade=‘F‘; } printf("Student Registered Successfully !!!\n"); index++; } //查看学生信息 void viewStudents() { int i=0; printf("Rollno name Address username password \n"); for(i=0;i<index;i++) printf("%d %s %s %s %s \n",studlist[i].rollno,studlist[i].name,studlist[i].address,
studlist[i].username,studlist[i].password); }
//查看学生分数 void viewMarks() { printf("English MAths Science Total AVERAGE Grade \n"); printf("%.2f %.2f %.2f %.2f %.2f %c \n",studlist[x].EnglishMarks,studlist[x].MathsMarks,
studlist[x].ScienceMarks,studlist[x].total,studlist[x].average,studlist[x].grade); } //退出 void exit() { system("cls"); void main(); } //字符串是否相等 int isEqual(char a[],char b[]) { int i,j,lenA,lenB; lenA=strlen(a); lenB=strlen(b); if(lenA==lenB) { for(i=0;i<lenA;i++) { if(a[i]!=b[i]) { return 0; } } return 1; } return 0; }
标签:style blog color io for div ar 管理
原文地址:http://www.cnblogs.com/thrive/p/3869807.html