can any one help me to write an algorithm for my program (c++) ?
pls
This would be better in the Computer Science area, but I can try.
#include<fstream.h> #include<iostream.h> #include<conio.h> class student { char name [25]; char grade; float marks; public: void getdata(void); void display(void); }; void student :: getdata(void) { char ch; cin.get(ch); cout<<"Enter name : "; cin.getline(name,25); cout<<"Enter grade : "; cin>>grade; cout<<"Enter marks : "; cin>>marks; cout<<"\n"; } void student :: display(void) { cout<<"NAME : ";puts(name); cout<<"MARKS : "<<marks; cout<<"GRADE : "<<grade; cout<<"\n"; } int main() { clrscr(); student arts[3]; fstream finlin; finlin.open("stu.dat",ios::in|ios :: out); if(!finlin) { cout<<"file cannot be opened !!!!!"; return 1; } cout<<"Enter details for 3 students "; for(int i=0;i<3;i++) { arts[i].getdata(); finlin.write((char *)&arts[i],size(arts[i])); } filin.seekg(0); file.close; return 0 }
What exactly are you trying to write here?
i am using a file program to input and display 3 student details
And what's going wrong for you?
i want to write the algoritm for this program
As far as I can tell, the algorithm is correct, you just have some errors you need to fix. At least, as far as inputting the student details. I can't see any part that displays the details.
k
i'll check it out thanks
To display them, it should be almost the same, but you use the display function in the class instead of the getdata
Join our real-time social learning platform and learn together with your friends!