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 DocumentRight 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(&quot;\n enter name &quot;); cin&gt;&gt;s.name; printf(&quot;\n enter 5 degree&quot;); for(int i=0;i&lt;5;i++) cin&gt;&gt;s.d[i]; return s; } //******* average function ********* float aver(int a) { float sum =0; for (int i=0;i&lt;5;i++) sum+=a[i]; return sum/5; } void main() { FILE *fp; fp=fopen(&quot;pass.txt&quot;,&quot;w+&quot;); int k=0; for(int i=0;i&lt;4;i++) {k=0; st[i]=read(); st[i].av =aver(st[i].d); for(int j=0;j&lt;5;j++) { if(st[i].d[j]&gt;49) k++; } if (k==5) fprintf(fp,&quot;\n%s %f &quot;,st[i].name ,st[i].av ); } fclose(fp); }...
View Full Document

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