structur and file

structur and file - struct student read student s...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Write a program which perform the following: 1- Define a structure named student with the following fields ( name, 5 degree ,average ) . 2- Define an array of structure with 4 elements . 3- Store the information for students in the array ( the average is computed in your program ). 4- Store the name and average for passed student in a file named ( pass.dat ). Note : (the student is passed if all his degree are greater than 49). #include<iostream.h> #include<stdio.h> #include<stdlib.h> struct student{ char name[20]; int d[5]; float av; }; student st[2]; // *********** reading structure ***************
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: struct student read() { student s; printf("\n enter name "); cin>>s.name; printf("\n enter 5 degree"); for(int i=0;i<5;i++) cin>>s.d[i]; return s; } //******* average function ********* float aver(int a) { float sum =0; for (int i=0;i<5;i++) sum+=a[i]; return sum/5; } void main() { FILE *fp; fp=fopen("pass.txt","w+"); int k=0; for(int i=0;i<4;i++) {k=0; st[i]=read(); st[i].av =aver(st[i].d); for(int j=0;j<5;j++) { if(st[i].d[j]>49) k++; } if (k==5) fprintf(fp,"\n%s %f ",st[i].name ,st[i].av ); } fclose(fp); }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

structur and file - struct student read student s...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online