Answer to Question #29330 in C++ for Nick

Question #29330
program that prints student number, name and marks and store them in a file?
1
Expert's answer
2013-04-30T08:52:59-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS