0% found this document useful (0 votes)
19 views5 pages

Lab Oop

Uploaded by

Swati Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Lab Oop

Uploaded by

Swati Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

question 3

#include<stdio.h>
struct employee
{
int id,age;
char name[20];
float salary;
};

int main()
{
int n295,i;
printf("Enter the number of employess \n");
scanf("%d",&n295);
struct employee s[n295];
float da295,hra295,total295;
printf("Enter the name,id,age,basic salary \n");
for(i=0;i<n295;i++)
{
printf("details of employee-%d\n",i+1);
scanf(" %[^\n]",s[i].name);
scanf(" %d",&s[i].id);
scanf(" %d",&s[i].age);
scanf(" %f",&s[i].salary);
}
for(i=0;i<n295;i++)
{
printf("employee-%d\n",i+1);
printf("name - %s\n", s[i].name);
printf("id - %d\n", s[i].id);
printf("age - %d\n", s[i].age);
da295=0.8 * s[i].salary;
hra295=0.1 * s[i].salary;
total295= s[i].salary + da295 + hra295;
printf("Gross salary - %.2f\n", total295);
printf("\n");
}
return 0;
}

question 2
#include<stdio.h>

struct student
{
char name[20];
int roll;
float marks[5],total,percentage;

};
void display(struct student s[],int n,int a)
{int check=0;
for(int i=0;i<n;i++)
{
check=0;
if(s[i].roll==a)
{
printf("name of student-%s\n",s[i].name);
printf("roll no of student-%d\n",s[i].roll);
for(int j=0;j<5;j++)
{
printf("marks of sub %d-%.2f\n",j+1,s[i].marks[j]);
}
printf("total marks and percentage are %.2f,
%.2f",s[i].total,s[i].percentage);
check=1;
}

}
if(check==0)
{

printf("student details not found");


}

}
void selesort(struct student s[],int n)
{int min;
for(int i=0;i<n;i++)
{
min=i;
for(int j=i+1;j<n;j++)
{
if(s[j].total<s[min].total)
{
min=j;
}
}
struct student temp;
temp=s[i];
s[i]=s[min];
s[min]=temp;

}
for(int i=0;i<n;i++)
{

printf("\nname of student-%s\n",s[i].name);
printf("roll no of student-%d\n",s[i].roll);
for(int j=0;j<5;j++)
{
printf("marks of sub %d-%.2f\n",j+1,s[i].marks[j]);
}

}
void find(struct student s[],int n,float lower,float upper)
{
int check=0;
for(int i=0;i<n;i++)
{
check=0;
if(s[i].percentage>=lower&&s[i].percentage<=upper)
{
printf("name of student-%s\n",s[i].name);
printf("roll no of student-%d\n",s[i].roll);
for(int j=0;j<5;j++)
{
printf("marks of sub %d-%.2f\n",j+1,s[i].marks[j]);
}
printf("total marks and percentage are %.2f,%.2f\
n",s[i].total,s[i].percentage);

check=1;
}
}
if(check==0)
{
printf("students details not found");
}

void calc(struct student s[],int n)


{

for(int i=0;i<n;i++)
{
int sum=0;
for(int j=0;j<5;j++)
{
sum=sum+s[i].marks[j];
s[i].total=sum;

} printf("total marks of student%d-%.2f\t",i+1,s[i].total);


s[i].percentage=(s[i].total)/5;
printf("and\tpercentage of the student is %.2f%\n",s[i].percentage);

int main()
{ int n295,ro295;
float lo295,up295;
printf("enter the no of students details to be entered");
scanf("%d",&n295);
struct student s[n295];
for(int i=0;i<n295;i++)
{
printf("enter the name of the student");
scanf(" %[^\n]",s[i].name);
printf("enter the roll no ");
scanf("%d",&s[i].roll);
printf("enter the marks of 5 subjects\n");
for(int j=0;j<5;j++)
{
printf("sub %d-",j+1);
scanf("%f",&s[i].marks[j]);
}
}
calc(s,n295);
printf("enter the roll no of the student whose details you want to check\t");
scanf("%d",&ro295);
display(s,n295,ro295);
printf("\n");
printf("enter the range of percentage between whose students details you want to
check\n");
printf("enter lower range");
scanf("%f",&lo295);
printf("enter upper range");
scanf(" %f",&up295);
find(s,n295,lo295,up295);
printf("\n##SORTING");
selesort(s,n295);
return 0;
}

question 1
#include<stdio.h>
struct student
{
char name[20];
int roll;
float marks[5];

};
int main()
{
struct student s295;
printf("enter the name of the student");
scanf("%[^\n]",s295.name);
printf("enter the roll no ");
scanf("%d",&s295.roll);
printf("engter the marks of 5 subjects\n");
for(int j=0;j<5;j++)
{
printf("sub %d-",j+1);
scanf("%f",&s295.marks[j]);
}
printf("display\n");
printf("name of student-%s\n",s295.name);
printf("roll no of student-%d\n",s295.roll);
for(int j=0;j<5;j++)
{
printf("marks of sub %d-%.2f\n",j+1,s295.marks[j]);
}
return 0;
}

You might also like