423,851 Members | 2,762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,851 IT Pros & Developers. It's quick & easy.

Create a enum to choose what operation need to be perfomed like (Display class inform

P: 1
What is the mistake in this program and the question is Create a enum to choose what operation need to be perfomed like (Display class information, show result, Fail students list, Pass students list ).
Create seperate function for each operation listed in above point.
Ask user to provide input and on the basis of user input call required function using function pointer.


#include<stdio.h>
#include<stdlib.h>
void Display_Information(char name1[],int date,int number,int mks[]);
void Show_result(char name1[],int date,int number,int mks[]);
void Pass_list(char name1[],int date,int number,int mks[]);
void Fail_list(char name1[],int date,int number,int mks[]);
enum ope{Display_Information=1,Show_result,Pass_list,Fa il_list};
enum ope info;
int main()
{
int n,name[50],dob,mks[5],i;
double mobile;
printf("Enter n value to enter student details: \n");
scanf("%d",&n);
printf("Enter %d student details: ",n);
printf("Enter Student name: ");
scanf("%s",name);
printf("Enter student birth date: ");
scanf("%d",&dob);
printf("Enter mobile number: ");
scanf("%lf",&mobile);
printf("Enter marks for 5 subjects: \n");
for(i=0;i<5;i++)
{
scanf("%d",&mks[i]);
}

void (*ptr_arr[])(char,int,int,int)={Display_Information,Show_resu lt,Pass_list,Fail_list};
int info;
printf("Student Record\n");
printf("1. Display_information\n");
printf("2. Show_result\n");
printf("3. Pass_list\n");
printf("4. Fail_list\n");
printf("Enter choice: \n");
scanf("%d",&info);
if(info>4)
return 0;
else
(*ptr_arr[info])(name,dob,mobile,mks);
return 0;
}
void Display_Information(char name1,int date,int number,int mks[])
{
int i;
printf("Given Information is: \n");
printf("Name: %s",name1);
printf("Date of birth is: %d",date);
printf("Mobile number is: %lf",number);
printf("Marks are :\n");
for(i=0;i<5;i++)
{
printf("%d ",mks[i]);
}
}
void Show_result(char name1,int date,int number,int mks[])
{
printf("%s marks are: \n",name1);
for(int i=0;i<5;i++)
{
printf("%d",mks[i]);
}
}
void Pass_list(char name1,int date,int number,int mks[])
{
printf("Pass marks are: \n");
for(int i=0;i<5;i++)
{
if(mks[i]>25)
{
printf("%d",mks[i]);
}
}
}
void Fail_list(char name1,int date,int number,int mks[])
{
printf("Fail marks are: \n");
for(int i=0;i<5;i++)
{
if(mks[i]<25)
{
printf("%d",mks[i]);
}
}
}
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,196
The first thing I see is that your enum value names are the same as your function names. The compiler now doesn't know what to do, so you get an error.


There may be other errors but fix this one first. All names in the code must be unique.
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.