Using file stream object, write a program to read an external text file ("myCourse.txt") which contains all the course name and numbers you are taking this semester, and to generate an analysis (total number of courses) into an external file ("myCourseSummay.txt").
This is a past question my teacher has been hinting at us to practice, so my friend and I made this and wanted to know if would be acceptable. Personally, I think we messed the writing to the .txt file.
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int intro()
{
cout << "Hello World!";
return 0;
}
int main()
{
ofstream myCourse;
myCourse.open("myCourse.txt");
char course1[20], course2[20], course3[20], course4[20];
cout << "Enter number of courses. max of 4" << endl;
cout << "Enter 1st course: ";
cin >> course1;
myCourse << course1 << endl;
cout << "Enter 2nd course: ";
cin >> course2;
myCourse << course2 << endl;
cout << "Enter 3rd course: ";
cin >> course3;
myCourse << course3 << endl;
cout << "Enter 4th course: ";
cin >> course4;
myCourse << course4 << endl;
myCourse.close();
ifstream myCourseSummary;
string word;
int count = 0;
myCourseSummary.open("myCourseSummary.txt");
while(!myCourseSummary.eof())
{
myCourseSummary >> word;
count++;
}
cout << "Total number if courses is(are) " << count << "!";
myCourseSummary.close();
cin.get();
return 0;
}