C-Program in Structure with Random Names and Marks Input of Students. (Working Code....)
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
char nm[][20]={
"Vikas",
"Vishwas",
"Prakash",
"Pradeep",
"Anil",
"Kamal",
"Harshit",
"Jay",
};
char na[][15]={
"joe",
"austin",
"henry",
"baker",
"chris",
};
struct student
{
int rollno,tot,avg,subm[4],max,min;
char fn[20],fa[15];
};
void sort(student [],int);
void sort(student s[100],int n)
{
int p,i,j,temp;
for(i=0;i<n-1;i++)
{
p=i;
for(j=i+1;j<n;j++)
{
if(s[p].rollno>s[j].rollno)
{
p=j;
}
}
temp=s[i].rollno;
s[i].rollno=s[p].rollno;
s[p].rollno=temp;
}
}
void input(student &s)
{
int x=random(8);
int y=random(5);
strcpy(s.fa,na[y]);
strcpy(s.fn,nm[x]);
s.rollno=random(100);
s.tot=0;
for(int i=0;i<4;i++)
{
s.subm[i]=random(71)+30;
s.tot+=s.subm[i];
}
s.avg=s.tot/4;
s.max=s.min=s.subm[1];
for(int j=0;j<4;j++)
{
if(s.subm[j]>s.max)
{
s.max=s.subm[j];
}
if(s.subm[j]<s.min)
{
s.min=s.subm[j];
}
}
}
void output(student &s)
{
printf("%-9s%-7s%d ",s.fn,s.fa,s.rollno);
for(int i=0;i<4;i++)
{
if(s.subm[i]>=33)
{
printf("%6d",s.subm[i]);
}
else
{
textcolor(RED+BLINK);
cprintf("%6d",s.subm[i]);
textcolor(7);
}
}
printf("%5d%4d%5d%5d",s.tot,s.avg,s.max,s.min);
int pa=0,f=0;
for(int j=0;j<4;j++)
{
if(s.subm[j]>=33)
{
pa++;
}
else
{
f++;
}
}
if(f==0 && pa!=0)
{
printf("%6s\n","pass");
}
else
{
printf("%6s\n","Fail");
}
}
void main()
{
student s[100];
int n,i,j,maxE,maxM,maxS,maxG;
clrscr();
printf("Enter the number of students :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
input(s[i]);
}
for(i=0;i<4;i++)
{
if(i==0) //for comparing english subject
{
maxE=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxE<s[j].subm[i])
maxE=s[j].subm[i];
}
}
else if(i==1)
{
maxM=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxM<s[j].subm[i])
maxM=s[j].subm[i];
}
}
else if(i==2)
{
maxS=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxS<s[j].subm[i])
maxS=s[j].subm[i];
}
}
else if(i==3)
{
maxG=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxG<s[j].subm[i])
maxG=s[j].subm[i];
}
}
}
printf("\n-------------------------Students details are as below---------------------\n\n");
printf(" NAME NO. Eng math sci guj TOt AVg max min Rank\n");
sort(s,n);
for(i=0;i<n;i++)
{
output(s[i]);
}
printf("\t\tmax:%6d%6d%6d%6d",maxE,maxM,maxS,maxG);
getch();
}
#include<conio.h>
#include<string.h>
#include<stdlib.h>
char nm[][20]={
"Vikas",
"Vishwas",
"Prakash",
"Pradeep",
"Anil",
"Kamal",
"Harshit",
"Jay",
};
char na[][15]={
"joe",
"austin",
"henry",
"baker",
"chris",
};
struct student
{
int rollno,tot,avg,subm[4],max,min;
char fn[20],fa[15];
};
void sort(student [],int);
void sort(student s[100],int n)
{
int p,i,j,temp;
for(i=0;i<n-1;i++)
{
p=i;
for(j=i+1;j<n;j++)
{
if(s[p].rollno>s[j].rollno)
{
p=j;
}
}
temp=s[i].rollno;
s[i].rollno=s[p].rollno;
s[p].rollno=temp;
}
}
void input(student &s)
{
int x=random(8);
int y=random(5);
strcpy(s.fa,na[y]);
strcpy(s.fn,nm[x]);
s.rollno=random(100);
s.tot=0;
for(int i=0;i<4;i++)
{
s.subm[i]=random(71)+30;
s.tot+=s.subm[i];
}
s.avg=s.tot/4;
s.max=s.min=s.subm[1];
for(int j=0;j<4;j++)
{
if(s.subm[j]>s.max)
{
s.max=s.subm[j];
}
if(s.subm[j]<s.min)
{
s.min=s.subm[j];
}
}
}
void output(student &s)
{
printf("%-9s%-7s%d ",s.fn,s.fa,s.rollno);
for(int i=0;i<4;i++)
{
if(s.subm[i]>=33)
{
printf("%6d",s.subm[i]);
}
else
{
textcolor(RED+BLINK);
cprintf("%6d",s.subm[i]);
textcolor(7);
}
}
printf("%5d%4d%5d%5d",s.tot,s.avg,s.max,s.min);
int pa=0,f=0;
for(int j=0;j<4;j++)
{
if(s.subm[j]>=33)
{
pa++;
}
else
{
f++;
}
}
if(f==0 && pa!=0)
{
printf("%6s\n","pass");
}
else
{
printf("%6s\n","Fail");
}
}
void main()
{
student s[100];
int n,i,j,maxE,maxM,maxS,maxG;
clrscr();
printf("Enter the number of students :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
input(s[i]);
}
for(i=0;i<4;i++)
{
if(i==0) //for comparing english subject
{
maxE=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxE<s[j].subm[i])
maxE=s[j].subm[i];
}
}
else if(i==1)
{
maxM=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxM<s[j].subm[i])
maxM=s[j].subm[i];
}
}
else if(i==2)
{
maxS=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxS<s[j].subm[i])
maxS=s[j].subm[i];
}
}
else if(i==3)
{
maxG=s[0].subm[i];
for(j=0;j<n;j++)
{
if(maxG<s[j].subm[i])
maxG=s[j].subm[i];
}
}
}
printf("\n-------------------------Students details are as below---------------------\n\n");
printf(" NAME NO. Eng math sci guj TOt AVg max min Rank\n");
sort(s,n);
for(i=0;i<n;i++)
{
output(s[i]);
}
printf("\t\tmax:%6d%6d%6d%6d",maxE,maxM,maxS,maxG);
getch();
}
No comments
Post your comments