Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can u please fix the in update score and display from big to small for me #include #include #include #include #include struct students{ char name[100];

can u please fix the in update score and display from big to small for me
#include
#include
#include
#include
#include
struct students{
char name[100];
char sex[100];
char id[100];
char age[100];
char grade[100];
int i;
char score[100];
char tel[100];
float math;
float physic;
float computer;
float khlanguage;
float history;
float sum;
float avg;
float mix;
};
struct students pd[100];
int i,n;
char filename[50];
void addInfo( ){
FILE*f1;
printf(" \tEnter student name: "); scanf("%s",&pd[n].name);
printf("\tEnter student ID: "); scanf("%s",&pd[n].id);
printf("\tEnter Gender: "); scanf("%s",&pd[n].sex);
printf("\tEnter student age: "); scanf("%s",&pd[n].age);
printf("\tEnter student grade: "); scanf("%s",&pd[n].grade);
printf("\tEnter telephone (+885): "); scanf("%s",&pd[n].tel);
i++;
f1 = fopen("student22.txt","a");
fprintf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
fclose(f1);
}
//function to search information of students by id
void searchInfo( ){
char id[100];
FILE*f1;
int flag=0;
f1 = fopen("student22.txt","r");
printf(" \t-------------------------------------------------------------------- ");
printf(" \tSEARCH ID:"); scanf("%s",id);
printf("\t-------------------------------------------------------------------- ");
printf("\tName\tid\tsex\tage\tgrade\ttelephone ");
printf("\t-------------------------------------------------------------------- ");
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
i++;
if(strcmp(pd[n].id,id)==0){
printf("\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
flag=1;
}
}
if(flag==0){
printf("\t*****NOT FOUND*****");
}
fclose(f1);
}
// function for display all students information
void displayInfo( ){
FILE*f1;
int i;
f1=fopen("student22.txt","r");
printf(" \t-------------------------------------------------------------------- ");
printf("\tName\tID\tSex\tAge\tGrade\tTel ");
printf("\t-------------------------------------------------------------------- ");
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
i++;
printf("\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
printf("\t-------------------------------------------------------------------- ");
}
fclose(f1);
}
// function for delete students informations
void deleteInfo(){
FILE*f1 ;
int id[100],f = 0 ,j;
int flag = 0;
int count = 0,n=0,index;
f1=fopen("student22.txt","r");
printf(" \tEnter ID :");scanf("%s",id);
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
if(strcmp(pd[n].id,id)==0){
printf(" \t\t---<<<<*** We found the student ID to be deleted ***>>>>--- ");
index = n;
}
count++;
n++;
}
n=0;
fclose(f1);
f1=fopen("student22.txt","w");
while(n < count){
if(index == n){
n++;
continue;
}else{
fprintf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
}
n++;
}
fclose(f1);
}
// functions for add score students
void addScore( ){
int k;
char id[100];
FILE*fs,*f1;
f1= fopen("student22.txt","r");
fs=fopen("students_score22.txt","a");
int status=0;
// printf("\tMath\tPhysic\tComputer\tKhmer\tHistory\tScore\tAverage\t ");
printf(" \t-------------------------------------------------------------------- ");
printf(" \tEnter id: ");scanf("%s",id);
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
if(strcmp(pd[i].id,id)==0){
status=1;
printf(" \tInput math score: "); scanf("%f",&pd[i].math);
printf("\tInput physic score: "); scanf("%f",&pd[i].physic);
printf("\tInput computer score: "); scanf("%f",&pd[i].computer);
printf("\tInput khmer score: "); scanf("%f",&pd[i].khlanguage);
printf("\tInput history score: "); scanf("%f",&pd[i].history);
pd[i].sum=pd[i].math + pd[i].physic + pd[i].computer + pd[i].khlanguage + pd[i].history;
pd[i].avg=pd[i].sum/5;
printf("\t*****UPDATE IS DONE***** ");
fprintf(fs," \t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f ",pd[i].id,pd[i].name,pd[i].math,pd[i].physic,pd[i].computer,pd[i].khlanguage,pd[i].history,pd[i].sum,pd[i].avg);
break;
}
}
if (status==0){
printf("\t*****NOT FOUND*****");
}
fclose(f1);
fclose(fs);
}
// update students informations
void updateInfo( ){
char id[100];
int status=0,i=0;
FILE*f1;
FILE *f2;
f1= fopen("student22.txt","r");
f2= fopen("student33.txt","w");
//printf("\tName\tID\tGender\tAge\tGrade\tTel ");
//printf("\t-------------------------------------------------------------------- ");
printf(" \tEnter ID: ");scanf("%s",id);
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
if(strcmp(pd[n].id,id)==0){
status=1;
printf(" \tNew student name: "); scanf("%s",&pd[n].name);
printf("\tNew student ID: "); scanf("%s",&pd[n].id);
printf("\tNew student gender: "); scanf("%s",pd[n].sex);
printf("\tNew Student age: "); scanf("%s",&pd[n].age);
printf("\tNew user grade: "); scanf("%s",&pd[n].grade);
printf("\tNew telephone (+885): "); scanf("%s",&pd[n].tel);
printf("\t*****UPDATE IS DONE***** ");
fprintf(f2,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
}
else{
fprintf(f2,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
}
i++;
}
if (status==0){
printf("\t*****NOT FOUND*****");
}
fclose(f1);
fclose(f2);
remove("student22.txt");
rename("student33.txt","student22.txt");
}
void updateScore(){
char id[100];
int status=0,i=0;
FILE*f3;
FILE *f4;
f3= fopen("students_score22.txt","r");
f4= fopen("student34.txt","w");
//printf("\tName\tID\tGender\tAge\tGrade\tTel ");
//printf("\t-------------------------------------------------------------------- ");
printf(" \tEnter ID: ");scanf("%s",id);
while(fscanf(f3," \t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f ",pd[i].id,pd[i].name,pd[i].math,pd[i].physic,pd[i].computer,pd[i].khlanguage,pd[i].history,pd[i].sum,pd[i].avg)!=EOF){
if(strcmp(pd[n].id,id)==0){
status=1;
printf(" \tInput math score: "); scanf("%f",&pd[i].math);
printf("\tInput physic score: "); scanf("%f",&pd[i].physic);
printf("\tInput computer score: "); scanf("%f",&pd[i].computer);
printf("\tInput khmer score: "); scanf("%f",&pd[i].khlanguage);
printf("\tInput history score: "); scanf("%f",&pd[i].history);
pd[i].sum=pd[i].math + pd[i].physic + pd[i].computer + pd[i].khlanguage + pd[i].history;
pd[i].avg=pd[i].sum/5;
printf("\t*****UPDATE IS DONE***** ");
fprintf(f4," \t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f ",pd[i].id,pd[i].name,pd[i].math,pd[i].physic,pd[i].computer,pd[i].khlanguage,pd[i].history,pd[i].sum,pd[i].avg);
}
else{
fprintf(f4," \t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f ",pd[i].id,pd[i].name,pd[i].math,pd[i].physic,pd[i].computer,pd[i].khlanguage,pd[i].history,pd[i].sum,pd[i].avg);
}
i++;
}
if (status==0){
printf("\t*****NOT FOUND*****");
}
fclose(f3);
fclose(f4);
remove("students_score22.txt");
rename("student34.txt","students_score22.txt");
}
//Function to update score
// function for display score students
void displayScore(){
char math[100],computer[100],physic[100],kh[100],his[100],sum[100],avg[100];
FILE*fs;
int count=0;
fs=fopen("students_score22.txt","r");
int i =0;
printf(" \tid\tname\tmath\tphysic\tcomputer kh\thistory\tSum\tAverage ");
printf("\t-------------------------------------------------------------------- ");
while(fscanf(fs,"\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s ",pd[i].id,pd[i].name, math, physic, computer, kh, his,sum,avg)!=EOF){
printf(" \t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s ",pd[i].id,pd[i].name,math,physic,computer,kh,his,sum,avg);
i++;
}
fclose(fs);
}
// function search male/female students informations
void searchGender(){
char sex[100];
int flag=0;
FILE*f1;
f1=fopen("student22.txt","r");
printf(" \tSEARCH GENDER(M/F):"); scanf("%s",sex);
printf("\tName\tID\tGender\tAge\tGrade\tTel ");
printf("\t-------------------------------------------------------------------- ");
// for(int i=0;i< n;i++){
// if(strcmp(pd[i].sex,sex)==0){
// flag=1;
// printf("\t%s\t%s\t%s\t%s\t%s\t%s ",pd[i].name,pd[i].id,pd[i].sex,pd[i].age,pd[i].grade,pd[i].tel);
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[i].name,pd[i].id,pd[i].sex,pd[i].age,pd[i].grade,pd[i].tel)!=EOF){
if(strcmp(pd[i].sex,sex)==0)
{
printf("\t%s\t%s\t%s\t%s\t%s\t%s ",pd[i].name,pd[i].id,pd[i].sex,pd[i].age,pd[i].grade,pd[i].tel);
flag=1;
}
}
if(flag==0){
printf("\t*****NOT FOUND*****");
}
n++;
fclose(f1);
}
// function for display score from big to small
void mix()
{
printf("\tID\tName\tSex\tAvg ");
printf("\t-------------------------------------------------------------------- ");
for(int k=pd[k].avg ;k>=0 ;k--)
{
{
printf("\t%s\t%s\t%s\t%f " ,pd[k].id,pd[k].name,pd[k].sex,pd[k].avg);
}
}
}
void loing_password()
{
char username[15];
char password[12];
printf("Enter your username: ");
scanf("%s",&username);
printf("Enter your password: ");
scanf("%s",&password);
if(strcmp(username,"chaitu")==0){
if(strcmp(password,"123")==0){
printf(" Welcome.Login Success!");
}else{
printf(" wrong password");
}
}
else{
printf(" User doesn't exist");
}
printf(" ");
}
void mun()
{
printf("\t\t\t\t |======================================================================| ");
printf("\t\t\t\t | WELCOME | ");
printf("\t\t\t\t | To | ");
printf("\t\t\t\t | STUDENT MANAGEMENT SYSTEM | ");
printf("\t\t\t\t | | ");
printf("\t\t\t\t |======================================================================| ");
printf("\t\t\t\t-----------------------------------------------------------------------------------------------------| ");
printf("\t\t\t\t|1) add students information. | 2)search information by id. | ");
printf("\t\t\t\t|----------------------------------------------------------------------------------------------------| ");
printf("\t\t\t\t|3) display all students information. | 4) update students information. | ");
printf("\t\t\t\t| ---------------------------------------------------------------------------------------------------| ");
printf("\t\t\t\t|5) for delete students informations. | 6) search male/female students informations. | ");
printf("\t\t\t\t|----------------------------------------------------------------------------------------------------| ");
printf("\t\t\t\t|7) add score student. | 8) display student score. | ");
printf("\t\t\t\t|----------------------------------------------------------------------------------------------------| ");
printf("\t\t\t\t|9) update score students. | 10) display score from big to small. | ");
printf("\t\t\t\t|----------------------------------------------------------------------------------------------------| ");
printf(" \t\t\t\t|11) Exit the program. | | ");
printf("\t\t\t\t|----------------------------------------------------------------------------------------------------|");
}
void loading( ) {
int i,j;
printf("Loading........");
for (i=1 ; i<= 20; i++){
for(j=0; j<=100000000; j++);
printf("%c",177);
}
}
// for call function use in main()
int main() {
system("color 0");
loing_password();
// loading();
int choice;
mun();
while(1){
printf(" ");
printf(" \tEnter Your Options: "); scanf("%d",&choice);
if(choice==1){
system("cls");
mun();
addInfo();
}
else if(choice==2){
system("cls");
mun();
searchInfo();
}
else if(choice==3)
{
system("cls");
mun();
displayInfo();
}
else if (choice==4)
{
system("cls");
mun();
updateInfo();
}
else if (choice==5)
{
system("cls");
mun();
deleteInfo();
}
else if (choice==6)
{
system("cls");
mun();
searchGender();
}
else if (choice==7)
{
system("cls");
mun();
addScore();
}
else if (choice==8)
{
system("cls");
mun();
displayScore();
}
else if (choice == 9)
{
system("cls");
mun();
printf(" ");
updateScore();
}
else if(choice == 10)
{
system("cls");
mun();
mix();
}
else if (choice==11)
{
system("cls");
mun();
printf("***** exit program*******");
break ;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions

Question

How does the scientific attitude contribute to critical thinking?

Answered: 1 week ago

Question

How to solve maths problems with examples

Answered: 1 week ago

Question

Explain Coulomb's law with an example

Answered: 1 week ago

Question

What is operating system?

Answered: 1 week ago