Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

someone help me finish this program

brjatjatbrjatjat Posts: 2Member
please help me finish my program....
please.....
------------------------------------------------
#include
#include
#include
#include
#include
#define p printf
#define s scanf

struct Group{
char name[15];
float scores[3];
struct Group *next;
};

typedef struct Group *ABDC;
ABDC first = NULL;

//file pointer(fp)
FILE *fp;

void loadGourps();//buffering
void addGroup();
void viewScoreSheet();
void changeGroupScores();
void deleteGroup();
void saveAllData();//flushing



main(){
loadGourps();

//menu
int choice;
int ctr=1;
do{
system("cls");
p("

Tabulation Tasks
=========================================
");
p(" [1]View Score Sheet
");
p(" [2]Register Group and Put Scores
");
p(" [3]Change Group Score
");
p(" [4]Delete Group
");
p(" [5]Save and Exit
");

p(" Task: ");
s("%i",&choice);

switch(choice){
case 1:
viewScoreSheet();
break;
case 2:
addGroup();
break;
case 3:
changeGroupScores();
break;
case 4:
deleteGroup();
break;
case 5:
saveAllData();
break;
default:
p("

No such Task...Press Enter Key");
getch();
}

}while(choice!=5);



p("

");
system("pause");
}

//buffering=====================================================================
void loadGourps(){
fp=fopen("groups.txt","r");

if(fp!=NULL){
while(!feof(fp)){
//need a line from file and create a node
ABDC newGrp = (ABDC)malloc(sizeof(struct Group));
fscanf(fp,"%s %f %f %f",&newGrp->name,&newGrp->scores[0],&newGrp->scores[1],&newGrp->scores[2]);
newGrp->next=NULL;

//link the node to the list
if(first==NULL){
first=newGrp;
}else{
ABDC last = first;
while(last->next!=NULL){
last = last->next;
}
last->next = newGrp;
}//end of else
}//end of while
}//end of if
fclose(fp);//closing file
}
//end of buffering==============================================================

void addGroup(){
system("cls");
ABDC newGrp = (ABDC)malloc(sizeof(struct Group));
p("

Create New Group
=========================================
");
p(" Crew: ");
s("%s",newGrp->name);

p(" Scores
|======================|
");
int i;
for(i=0;i<3;i++){
p(" | Judge %i: ",i+1);
s("%f",&newGrp->scores[i]);
}
p(" |======================|
");
newGrp->next=NULL;
if(first==NULL){
first=newGrp;
}else{
ABDC last = first;
while(last->next!=NULL){
last = last->next;
}
last->next = newGrp;
}//end of else

p("
Succesfully added new group
");
p("
Back to menu...Press Enter Key");
getch();
}

void viewScoreSheet(){
system("cls");
p("

Score Sheet
=========================================
");
ABDC grp = first;
int count = 1;
while(grp!=NULL){
p(" %i] %s %.2f %.2f %.2f
",count++,grp->name,grp->scores[0],grp->scores[1],grp->scores[2]);
grp = grp->next;
}
p("
Back to menu ... Press Enter Key");
getch();
}


void changeGroupScores(){}

void deleteGroup(){

system("cls");
int choice;
p("

Score Sheet
=========================================
");
ABDC grp = first;
int count = 1;
while(grp!=NULL){
p(" %i] %s %.2f %.2f %.2f
",count++,grp->name,grp->scores[0],grp->scores[1],grp->scores[2]);
grp = grp->next;
}

p("Enter Group No. You Want To Delete: ");
s("%i",&choice);

ABDC before=first;
ABDC toBeDeleted=before->next;
ABDC after=toBeDeleted->next;
int ctr=1;
while(ctrnext;
toBeDeleted=before->next;
after=toBeDeleted->next;
ctr++;
}
before->next=after;
free(toBeDeleted);

viewScoreSheet();
}

//flushing or saving
void saveAllData(){
fp=fopen("groups.txt","w");
ABDC grp = first;
while(grp!=NULL){
fprintf(fp,"%s %.2f %.2f %.2f",grp->name,grp->scores[0],grp->scores[1],grp->scores[2]);
if(grp->next!=NULL){
fprintf(fp,"
");
}
grp = grp->next;
}
//fclose(fp);//closing file

}

Sign In or Register to comment.