Professional Documents
Culture Documents
Structure
Structure
WAP to declare a structure stud to store marks of 5 subjects & find sum and avg.
#include<iostream.h> #include<stdio.h> #include<conio.h> struct student { int roll; char name[20]; int marks[5]; int sum,avg; }s1; void main() { clrscr(); int i; cout<<"enter roll no. "; cin>>s1.roll; cout<<"enter name: "; gets(s1.name); for(i=0;i<5;i++) { } for(i=0;i<5;i++) { } cout<<endl<<"total marks= "<<s1.sum; s1.avg=(s1.sum)/5; cout<<endl<<"avg marks= "<<s1.avg; getch(); } s1.sum=s1.sum+s1.marks[i]; cout<<"enter marks of subject: "; cin>>s1.marks[i];
WAP to declare a structure student with following fields roll, name and marks. Enter data for 5 students.
#include<iostream.h> #include<stdio.h> #include<conio.h> struct student { int roll; char name[20]; int marks; }s1[5]; void main() { clrscr(); int i; for(i=0;i<5;i++) { cout<<endl<<"enter roll no. "; cin>>s1[i].roll; cout<<"enter name: "; gets(s1[i].name); cout<<"enter marks: "; cin>>s1[i].marks; } getch(); }
WAP to declare a structure student with following fields ecode, ename and ephone Enter data for 5 employees.
#include<iostream.h> #include<stdio.h> #include<conio.h> struct employee { int ecode; char ename[20]; int ephone; }e1[5]; void main() { clrscr(); int i,ph; for(i=0;i<5;i++) { cout<<endl<<"enter ecode: "; cin>>e1[i].ecode; cout<<"enter ename: "; gets(e1[i].ename); cout<<"enter ephone: "; cin>>e1[i].ephone; } cout<<endl<<"enter phone no. to be searched: "; cin>>ph; for(i=0;i<5;i++) { if(e1[i].ephone==ph) { cout<<"person having above phone no is: "; puts(e1[i].ename); }
} getch(); }
WAP to declare a structure student with following fields ecode, ename and eaddress (house no, city, state)
#include<iostream.h> #include<stdio.h> #include<conio.h> struct address { int h_no; char city[20]; char state[20]; }; struct employee { char ename[20]; int ephone; address a1; }e1,e2; void main() { clrscr(); cout<<"enter ename: "; gets(e1.ename); cout<<"enter ephone: "; cin>>e1.ephone; cout<<"enter house no: "; cin>>e1.a1.h_no; cout<<"enter city: "; gets(e1.a1.city); cout<<"enter state: "; gets(e1.a1.state);
cout<<endl<<"enter ename: "; gets(e2.ename); cout<<"enter ephone: "; cin>>e2.ephone; cout<<"enter house no: "; cin>>e2.a1.h_no; cout<<"enter city: "; gets(e2.a1.city); cout<<"enter state: "; gets(e2.a1.state); getch(); }