In: Computer Science
Im asked to edit the C++ code given to me so that the user can enter as many courses as they would like.
I've already built the array to house the courses, but Im a tiny bit stuck on writing the user input to the array every time a new line Is made.
Code:
//CSC 211 Spring 2019
//Program Description:
//
// Originally From:
// CSC 211 Spring 2018
// Dr. Sturm
// This program...
//
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
// outputHtmlTitle
// parameters
// This function...
void outputHtmlTitle(ofstream & fout, string title){
fout << "<!DOCTYPE html>" << endl;
fout << "<body style = \"background-color:yellow;\">" << endl;
fout << "<html>" << endl;
fout << "<title>" << endl;
fout << title << endl;
fout << "</title>" << endl;
}
void outputHtmlFooter(ofstream & fout){
fout << "</body>" << endl;
fout << "</html>" << endl;
}
void outputHtmlList(ostream & fout, string first, string second, string third){
fout << "<ul>" << endl;
fout << "\t<li>" << first << "</li>" << endl;
fout << "\t<li>" << second << "</li>" << endl;
fout << "\t<li>" << third << "</li>" << endl;
fout << "\t</ul>" << endl;
}
int main(int argc, char * *argv){
ofstream htmlFile("myIntro.html");
string title;
string t;
cout << "Please enter the title: ";
getline(cin, title);
outputHtmlTitle(htmlFile, title);
string name;
char courses[50] = {"", "", "", "", "", "", "", "", "", "", ""};
cout << "Please enter your name: ";
getline(cin, name);
htmlFile << "<h2>" << "My name is " << name << "</h2>" << endl;
cout << "Please enter the courses you are taking; one per line" << endl;
for(t = courses[0];t < courses[50];courses[]++) {
cin.getline(courses[t]);
};
htmlFile << "<h3>" << "This semester I am taking: " << "</h3>" << endl;
outputHtmlList(htmlFile, courses[1], course[2], courses[3], courses[4], courses[5], courses[6], courses[7], courses[8]);
outputHtmlFooter(htmlFile);
}
If you have any doubts, please give me comment...
//CSC 211 Spring 2019
//Program Description:
//
// Originally From:
// CSC 211 Spring 2018
// Dr. Sturm
// This program...
//
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
// outputHtmlTitle
// parameters
// This function...
void outputHtmlTitle(ofstream &fout, string title)
{
fout << "<!DOCTYPE html>" << endl;
fout << "<body style = \"background-color:yellow;\">" << endl;
fout << "<html>" << endl;
fout << "<title>" << endl;
fout << title << endl;
fout << "</title>" << endl;
}
void outputHtmlFooter(ofstream &fout)
{
fout << "</body>" << endl;
fout << "</html>" << endl;
}
void outputHtmlList(ostream &fout, string courses[], int n)
{
fout << "<ul>" << endl;
for(int i=0; i<n; i++){
fout << "\t<li>" << courses[i] << "</li>" << endl;
}
fout << "</ul>" << endl;
}
int main(int argc, char **argv)
{
ofstream htmlFile("myIntro.html");
string title;
int t;
cout << "Please enter the title: ";
getline(cin, title);
outputHtmlTitle(htmlFile, title);
string name;
string courses[50] ={""};
cout << "Please enter your name: ";
getline(cin, name);
htmlFile << "<h2>"
<< "My name is " << name << "</h2>" << endl;
cout << "Please enter the courses you are taking; one per line(leave empty to exit)" << endl;
for (t = 0; t < 50; t++)
{
getline(cin, courses[t]);
if(courses[t]=="")
break;
};
htmlFile << "<h3>"
<< "This semester I am taking: "
<< "</h3>" << endl;
outputHtmlList(htmlFile, courses, t);
outputHtmlFooter(htmlFile);
htmlFile.close();
}