Question

In: Computer Science

1)     The provided sched.cpp file is missing a few lines to read in some of the data....

1)     The provided sched.cpp file is missing a few lines to read in some of the data. The comments in the code describe how there is yet another stream library that works like iostream and fstream, but for processing string’s. Fill in the necessary statements and uncomment the indicated cout statements to get the output below for the attached “sched.txt” file:

CS100

Section 1 has 17 open seats

It is held on MW from 8:00A to 9:15A in SC-S146

It is taught by C. Smith

Section 2 has 11 open seats

It is held on MW from 11:00A to 12:15P in VBT-0222

It is taught by I. Yellapragada


sched.cpp
/* Lab 4 part 1. Files and stringstreams */
#include <iostream>
#include <fstream>
#include <sstream> // like fstream, but for string's
#include <iomanip>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
    string dept, crsInfo, secInfo, days, room, lname, finit;
    unsigned int crsNo, secNo, cap, avail, start_hr, start_min, end_hr, end_min;
    char skip, start_ampm, end_ampm;
    ifstream sched("sched.txt");
    istringstream secStrm;

    // Read in Course department, number
    sched >> dept >> crsNo;
    // Note that >> does not store the space between
    // dept and crsNo
    cout << dept << crsNo << endl;
    getline(sched, crsInfo);
    sched.ignore(1);

    // Process each section
    while (sched >> secNo) {
        // Reads rest of line from file into string
        getline(sched, secInfo);
        // Set the stringstream to take its data
        // from this string
        secStrm.clear(); // first clear what's in the stream
        secStrm.str(secInfo); // now set the data to process
        // Now you can use the usual >> operator
        secStrm >> cap >> skip >> avail;
        // ADD CODE HERE
        // use the skip char variable to read in extra char's
        // or use ignore()

        cout << "Section " << secNo
             << " has " << avail << " open seats" << endl;
        // Uncomment the following to get the rest of the output
        // after you have extracted these values
        /*
        cout << "It is held on " << days
             << " from " << start_hr << ':'
             << setw(2) << setfill('0')
             << start_min << start_ampm
             << " to " << end_hr << ':'
             << setw(2) << setfill('0')
             << end_min << end_ampm
             << " in " << room << endl
             << "It is taught by " << finit << ' ' << lname << endl;
        */
        // Get to start of next line in file
        sched.ignore(1);
    }
    sched.close();
    // system("pause");
        return 0;
}

sched.txt

CS 100 - Programming for Everyone (3 Units) 
01   45/17  MW  SC-S146    08:00A-09:15A Smith C.
02   45/11  MW  VBT-0222   11:00A-12:15P Yellapragada I.

Solutions

Expert Solution

If you have any doubts, please give me comment...

/* Lab 4 part 1. Files and stringstreams */

#include <iostream>

#include <fstream>

#include <sstream> // like fstream, but for string's

#include <iomanip>

#include <cstdlib>

#include <string>

using namespace std;

int main()

{

    string dept, crsInfo, secInfo, days, room, lname, finit, temp;

    unsigned int crsNo, secNo, cap, avail, start_hr, start_min, end_hr, end_min;

    char skip, start_ampm, end_ampm;

    ifstream sched("sched.txt");

    istringstream secStrm;

    // Read in Course department, number

    sched >> dept >> crsNo;

    // Note that >> does not store the space between

    // dept and crsNo

    cout << dept << crsNo << endl;

    getline(sched, crsInfo);

    sched.ignore(1);

    // Process each section

    while (sched >> secNo) {

        // Reads rest of line from file into string

        getline(sched, secInfo);

        // Set the stringstream to take its data

        // from this string

        secStrm.clear(); // first clear what's in the stream

        secStrm.str(secInfo); // now set the data to process

        // Now you can use the usual >> operator

        secStrm >> cap >> skip >> avail>>days>>room>>temp>>lname>>finit;

        start_hr = stoi(temp.substr(0, 2));

        start_min = stoi(temp.substr(3, 2));

        start_ampm = temp[5];

        end_hr = stoi(temp.substr(7, 2));

        end_min = stoi(temp.substr(10, 2));

        end_ampm = temp[12];

        // ADD CODE HERE

        // use the skip char variable to read in extra char's

        // or use ignore()

        cout << "Section " << secNo

             << " has " << avail << " open seats" << endl;

        // Uncomment the following to get the rest of the output

        // after you have extracted these values

        cout << "It is held on " << days

             << " from " << start_hr << ':'

             << setw(2) << setfill('0')

             << start_min << start_ampm

             << " to " << end_hr << ':'

             << setw(2) << setfill('0')

             << end_min << end_ampm

             << " in " << room << endl

             << "It is taught by " << finit << ' ' << lname << endl;

        // Get to start of next line in file

        sched.ignore(1);

    }

    sched.close();

    // system("pause");

        return 0;

}


Related Solutions

. A VERY BRIEF EXPLANATION ( FEW WORDS/1-2 LINES/RELEVANT GRAPH MUST BE PROVIDED FOR A TRUE...
. A VERY BRIEF EXPLANATION ( FEW WORDS/1-2 LINES/RELEVANT GRAPH MUST BE PROVIDED FOR A TRUE (T) RESPONSE AS WELL. (a) Legalizing all forms of illegal activities will have an effect on GDP and underground economy. (b) “Star Wars: The Force Awakens broke all the records in terms of Gross earnings” But it was no “Gone with the Wind. (c) Laissez Faire means “Let people do what they choose to do”. This means no role for government (d) USA has...
I need this in java using textpad. I am missing a few lines where I added...
I need this in java using textpad. I am missing a few lines where I added in comments. I don't know what I need to add in. Here are the two programs as pasteable code.The comments in the code say what I need done. The two programs are below. I need it to work with the generic version of SLLNode. It is posted at the bottom. public class ListDemoHw { public static void printLinkedList(SLLNode node) { // display all elements...
I need this in java using textpad. I am missing a few lines where I added...
I need this in java using textpad. I am missing a few lines where I added in comments. I don't know what I need to add in. Here are the two programs as pasteable code.The comments in the code say what I need done. The two programs are below. public class ListDemoHw { public static void printLinkedList(SLLNode node) { // display all elements in the linked list while(node != null) { System.out.print(node.info + " "); node = node.next; // move...
Use the Main.java file below to read in phrases (entire lines!) and print underscores "_" for...
Use the Main.java file below to read in phrases (entire lines!) and print underscores "_" for each character. Main.java already imports the Scanner class, creates your Scanner object, and reads in the first phrase from the keyboard. Your task is as followed: import java.util.Scanner; public class Main {    public static void main(String[] args) {        Scanner keyboard = new Scanner(System.in);        String phrase = keyboard.nextLine();           //Your code here!    } } Write a nested...
Minimizing missing data: Here are some types of missing data that you might encounter when implementing...
Minimizing missing data: Here are some types of missing data that you might encounter when implementing a clinical trial. Pick two, and briefly describe a study procedure you could use to minimize the chance of that type of missing data occurring. 1. A participant does not show up for a study visit. 2. A participant does not bring important information (for example, a list of current medications or a pain diary that was supposed to be filled out). 3. Inadequate...
Write a Fortran program that is able to read in the data file. The file has...
Write a Fortran program that is able to read in the data file. The file has lines with the structure: 19990122 88888 30.5 Where: i) the first is an 8 digit code with the date: yyyymmdd (yyyy is the year, mm is the month, and dd is the day) ii) the second is the five digit odometer reading of a car iii) the third is the amount of fuel put into the car on that date to fill the tank...
Download the file data.csv (comma separated text file) and read the data into R using the...
Download the file data.csv (comma separated text file) and read the data into R using the function read.csv(). Your data set consists of 100 measurements in Celsius of body temperatures from women and men. Use the function t.test() to answer the following questions. Do not assume that the variances are equal. Denote the mean body temperature of females and males by μFμF and μMμMrespectively. (a) Find the p-value for the test H0:μF=μMH0:μF=μM versus HA:μF≠μM.HA:μF≠μM. Answer (b) Are the body temperatures...
Implement an application that will read data from an input file, interpret the data, and generate...
Implement an application that will read data from an input file, interpret the data, and generate the output to the screen. - The application will have two classes, Rectangle and Lab2ADriver. - Name your Eclipse project, Lab2A. Implement the Rectangle class with the following description. Rectangle Data fields -numRows: int -numCols: int -filled: Boolean Store the number of rows in the Rectangle Store the number of columns in the Rectangle Will define either a filled or unfilled rectangle True =...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided above. The program should sum all the numbers, find the lowest number, find the highest number, and computer the average. Upon completion of the processing, the program should write a new text file named stats.txt with the information found in the following format where xxx represents a number calculated above. The sum of the numbers is: xxx The lowest number is: xxx The highest...
Exercise 2: You are provided with a text file named covid19-3.txt. It reports a few confirmed...
Exercise 2: You are provided with a text file named covid19-3.txt. It reports a few confirmed cases of covid19. It consists of three columns. The 1st column indicates the names of the provinces, the 2nd column indicates the names of the countries and the 3rd column indicates the numbers of confirmed cases. To do: 1. Define a function that reads, from covid19-3.txt, provinces, countries and confirmed cases in three separate lists. 2. Define a function that iterates through a list...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT