In: Computer Science
void main()
{
Grade g1; //object for grade
char h;
cout << "enter character" ;
cin>>h; //getting value
g1.grade(h);
g1.print();
getch();
}
create an output file (named “output.txt”), and save the character to this output file. Last, close this output file
#include <fstream>
#include <iostream>
#include<conio.h>
using namespace std;
class Grade { // The class
public: // Access specifier
void grade(char h) {
ofstream file;
file.open("output.txt");
file<<h; //writing character to file output.txt
file.close(); //closing file
}
void print(){
ifstream infile;
char ch;
infile.open("output.txt"); //open output.txt file
infile>>ch; //reading character from file
cout<<"printing character:"<<ch;
}
};
int main()
{
Grade g1; //object for grade
char h;
cout << "enter character: " ;
cin>>h; //getting value
g1.grade(h); //calling grade method inside Grade class
g1.print(); //calling print method
getch();
return 0;
}
OUTPUT
output.txt file