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...
Make a program to read a file, filled with words separated by new lines, from command...
Make a program to read a file, filled with words separated by new lines, from command line arguments (args[0]), print the file, and then add each word into an arraylist. After making the arraylist, iterate through it and print its contents.
1)     The provided reorder.cpp file has some code for a function that reorders the values in 3...
1)     The provided reorder.cpp file has some code for a function that reorders the values in 3 parameters so that they are in ascending order. ·Start with a function void swap(int &val1, int &val2) that swaps the values of val1 and val2. You will need a local variable to hold the value of one of the parameters to let you do this. ·Write the reorder function called in main(). It should call swap() to exchange values when appropriate. ·Add statements to...
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 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT