Question

In: Computer Science

Im asked to edit the C++ code given to me so that the user can enter...

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);

}

Solutions

Expert Solution

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();

}


Related Solutions

edit the code to make sure that if the user enter any city coordinates out the...
edit the code to make sure that if the user enter any city coordinates out the ranges ( x and y should be between 1 and 25). Also write the calc_plant() method in different way. import java.io.*; import java.util.*; public class State {    private int citi1x,citi1y; private int pop1; private int citi2x,citi2y; private int pop2; private int citi3x,citi3y; private int pop3; private int citi4x,citi4y; private int pop4; private int plantx,planty; public int getCity1X(){ return citi1x; } public int getCity1Y(){...
C++ Write the C++ code for a void function that prompts the user to enter a...
C++ Write the C++ code for a void function that prompts the user to enter a name, and then stores the user's response in the string variable whose address is passed to the function. Name the function getName.
Python 3 Fix the code so if the user enter the same bar code more than...
Python 3 Fix the code so if the user enter the same bar code more than three times, it shows a warning message indicating that the product was already tested 3 times and it reached the limits Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1, weight=1) window.grid_rowconfigure(1, weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20,...
Python 3 Fix the code so if the user enter the same bar code more than...
Python 3 Fix the code so if the user enter the same bar code more than three times, it shows a warning message indicating that the product was already tested 3 times and it reached the limits Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window,...
using C++. edit this code down below so that it will implement stack with linked list...
using C++. edit this code down below so that it will implement stack with linked list contains a default constructor, a copy constructor, and a destructor. #include <iostream> #include <vector> #include <string> #include <stack> #include <limits> using namespace std; class Stack { public: bool isEmpty(); int top(); int pop(); void push(int); void printList(); private: vector<int> elements; }; bool Stack::isEmpty() { return elements.empty(); } int Stack::top() { if(isEmpty()) { throw runtime_error("error: stack is empty"); } return elements.back(); } int Stack::pop() {...
In c++, modify this program so that you allow the user to enter the min and...
In c++, modify this program so that you allow the user to enter the min and maximum values (In this case they cannot be defined as constants, why?). // This program demonstrates random numbers. #include <iostream> #include <cstdlib> // rand and srand #include <ctime> // For the time function using namespace std; int main() { // Get the system time. unsigned seed = time(0); // Seed the random number generator. srand(seed); // Display three random numbers. cout << rand() <<...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code should print the numbers in descending order.
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
Please code C# 8. Write a program that prompts the user to enter an integer. The...
Please code C# 8. Write a program that prompts the user to enter an integer. The program then determines and displays the following: Whether the integer is divisible by 5 and 6 Whether the integer is divisible by 5 or 6
c++ code: prompt user to enter a number then add loop that checks a list of...
c++ code: prompt user to enter a number then add loop that checks a list of numbers then display numbers that are higher or equal to the user's input.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT