67 095
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #26488 in C++ for Pranav

Question #26488
Writing a program to print student roll no., name , marks and store in a file?
Expert's answer
writing a program to print student roll no., name , marks and store in a file?

#include<iostream>
#include<conio.h>
#include<string.h>

struct StudStruct{
& char name[50];
& int marks[3];
& int total;
& int average;
& };

int N, i, j;
char answer;
StudStruct student[100];

void input(){
N=0;
answer = 'R';
while (answer!='Q'){
std::cout<<"\nPress N to add new student and Q to stop adding students: ";
std::cin>>answer;
if (answer=='Q'){
break;
}
if (answer=='N'){
std::cout<<"Input student's name: ";
std::cin>>student[N].name;
std::cout<<"Input first mark:";
std::cin>>student[N].marks[0];
std::cout<<"Input second mark:";
std::cin>>student[N].marks[1];
std::cout<<"Input third mark:";
std::cin>>student[N].marks[2];
N++;
}
if ((answer!='N')&&(answer!='Q')){
std::cout<<"Please, enter valid answer\n\n";
}
}
}

void print(){
if (N==0) std::cout<<"Please enter one student at least";
else
for (i=0;i<N;i++){
std::cout<<"st. no. "<<i+1<<": "<<student[i].name<<student[i].marks[0]<<student[i].marks[1]<<student[i].marks[2]<<"\n";
}
}

void save (){
FILE *f;
f=fopen("students.txt","w");
for(int i=0; i<N; i++)
fprintf(f, "%d %s %d %d %d\n", i+1, student[i].name, student[i].marks[0], student[i].marks[1], student[i].marks[2]);
fclose(f);
}

void main(){
input();
print();
save();
getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions