1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
timofeeve [1]
3 years ago
9

In this milestone we will create a Course class to represent a course and display its information on the screen. We will create

two global functions that will validate the courses in a schedule file and store it in an array of Course objects, and display information from an array of Course objects.
Engineering
1 answer:
son4ous [18]3 years ago
4 0

Answer:

Code is given below:

Explanation:

Please enter the file name containing the list of classes: sched.txt

Schedule file loaded. Displaying contents ...

Course name: CPSC 131

Location: EC 109

Weekly schedule: MW

Start time: 16:00

End time: 17:15

Course name: CPSC 481

Location: CS 408

Weekly schedule: MW

Start time: 16:00

End time: 17:15

Course name: CPSC 362

Location: CS 101

Weekly schedule: MW

Start time: 8:00

End time: 9:50

Thank you for using Tuffy Scheduler.

Start time happens after end time

cources.txt

CPSC 131,EC 109,MW,16:00,17:15

CPSC 481,CS 408,MW,16:00,17:15

CPSC 362,CS 101,MW,8:00,9:50

#include <iostream>

#include <fstream>

#include <sstream>

#include<vector>

using namespace std;

class Course {

private:

  std::string course_name_;

  std::string location_;

  std::string weekly_schedule_;

  int start_time_;

  int end_time_;

public:

  const std::string& getCourseName() const {

      return course_name_;

  }

  void setCourseName(const std::string& courseName) {

      course_name_ = courseName;

  }

  const std::string getEndTime() const {

      std::string st = to_string(end_time_);

      std::string st2 = st.substr(st.length() - 2);

      //cout << st2 << '\n';

      size_t found = st.find(st2);

      std::string st1 = st.substr(0, found);

      std::string st3 = st1 + ":" + st2;

      return st3;

  }

  void setEndTime(int endTime) {

      end_time_ = endTime;

  }

  const std::string& getLocation() const {

      return location_;

  }

  void setLocation(const std::string& location) {

      location_ = location;

  }

  const std::string getStartTime() const {

      std::string st = to_string(start_time_);

      std::string st2 = st.substr(st.length() - 2);

      //cout << st2 << '\n';

      size_t found = st.find(st2);

      std::string st1 = st.substr(0, found);

      std::string st3 = st1 + ":" + st2;

      return st3;

  }

  void setStartTime(int startTime) {

      start_time_ = startTime;

  }

  const std::string& getWeeklySchedule() const {

      return weekly_schedule_;

  }

  void setWeeklySchedule(const std::string& weeklySchedule) {

      weekly_schedule_ = weeklySchedule;

  }

  void display() {

      cout << "Course name: " << course_name_ << endl;

      cout << "Location: " << location_ << endl;

      cout << "Weekly schedule: " << weekly_schedule_ << endl;

      cout << "Start time:" << getStartTime() << endl;

      cout << "End time:" << getEndTime() << endl;

  }

};

bool load_schedule(std::string fileName, Course (&courses)[100], int& curSize);

int main() {

  cout << "Welcome to Tuffy Scheduler!" << endl;

  cout << "Please enter the file name containing the list of classes:"

          << endl;

  std::string fileName;

  Course courses[100];

  int curSize = 0;

  cin >> fileName; // provide complete path ex D:\\Chegg\\CheggCpp\\src\\cources.txt

  if (load_schedule(fileName, courses, curSize)) {

      cout << "Schedule file loaded. Displaying contents ..." << endl<<endl;

      int i;

      //cout << curSize << '\n';

      for (i = 0; i < curSize; i++) {

          courses[i].display();

          cout << endl;

      }

      cout << "Thank you for using Tuffy Scheduler."<< endl;

      cout << "Start time happens after end time"<< endl;

  } else {

      cout << "Invalid file" << endl;

  }

  return 0;

}

bool load_schedule(std::string fileName, Course (&courses)[100], int& curSize) {

  ifstream myfile(fileName);

  string line;

  //cout << fileName << '\n';

  if (myfile.is_open()) {

      while (getline(myfile, line)) {

          stringstream ss(line);

          vector<string> v;

          while (ss.good()) {

              string substr;

              getline(ss, substr, ',');

              v.push_back(substr);

          }

          Course c;

          c.setCourseName(v[0]);

          c.setLocation(v[1]);

          c.setWeeklySchedule(v[2]);

          if (v[2] != "MW") {

              cout << "Error: Invalid weekly schedule symbol " << v[2]

                      << '\n';

              return false;

          }

          //set start time

          string startTime = v[3];

          size_t found = startTime.find(":");

          startTime.erase(found, 1);

          //cout << startTime << '\n';

          stringstream st(startTime);

          int startTimeInt = 0;

          st >> startTimeInt;

          c.setStartTime(startTimeInt);

          //set end time

          string endTime = v[4];

          found = endTime.find(":");

          endTime.erase(found, 1);

          // cout << endTime << '\n';

          stringstream st1(endTime);

          int endTimeInt = 0;

          st1 >> endTimeInt;

          c.setEndTime(endTimeInt);

          if (startTimeInt > endTimeInt) {

              cout << "Error: The start time " << startTimeInt

                      << "should happen before the end time " << endTimeInt

                      << '\n';

              return false;

          }

          courses[curSize] = c;

          curSize++;

          //cout << curSize << '\n';

      }

      myfile.close();

  }

  return true;

}

You might be interested in
In the following code, determine the values of the symbols here and there. Write the object code in hexadecimal. (Do not predict
allsm [11]

Answer:

Answer explained below

Explanation:

The value of here is 9

The value of there is hexadecimal value of DECO here, d = 0x39 aaaa (aaaa is the memory address of here )

We have the object code :-

let's take there address is 0x0007

0x0005 BR there :- 0x120020

0x0007 here: .WORD 9

310003 there: DECO here,d - 0x390007

310005 STOP

.END

4 0
3 years ago
Am i eating ramon nooddles rn
Elden [556K]

Answer:

You are eating ramen

Explanation:

It is shrimp flavor, yee yee

3 0
3 years ago
Read 2 more answers
Write a program that asks the user to input a vector of integers of arbitrary length. Then, using a for-end loop the program exa
ELEN [110]

Answer:

%Program prompts user to input vector

v = input('Enter the input vector: ');

%Program shows the value that user entered

fprintf('The input vector:\n ')

disp(v)

%Loop for checking all array elements

for i = 1 : length(v)

   %check if the element is a positive number

   if v(i) > 0

       %double the element

       v(i) = v(i) * 2;

   %else the element is negative number.

   else

       %triple the element

       v(i) = v(i) * 3;

   end

end

%display the modified vector

fprintf('The modified vector:\n ')

disp(v)

4 0
3 years ago
A 225 MPa conducted in which the mean stress was 50 MPa and the stress amplitude was (a) Compute the maximum and (b) Compute the
tamaranim1 [39]

Answer:

Explanation:

Given data in question

mean stress  = 50 MPa

amplitude stress  = 225 MPa

to find out

maximum stress, stress ratio, magnitude of the stress range.

solution

we will find first  maximum stress  and minimum stress

and stress will be sum of (maximum +minimum stress) / 2

so for stress 50 MPa and 225 MPa

\sigma _{m} =  \sigma _{maximum} + \sigma _{minimum}  / 2

50 =  \sigma _{maximum} + \sigma _{minimum}  / 2    ...........1

and

225 =  \sigma _{maximum} + \sigma _{minimum}  / 2      ...........2

from eqution 1 and 2 we get maximum and minimum stress

\sigma _{maximum} = 275 MPa        ............3

and \sigma _{minimum} = -175 MPa     ............4

In 2nd part we stress ratio is will compute by ratio of equation 3 and 4

we get ratio =  \sigma _{minimum} / \sigma _{maximum}

ratio = -175 / 227

ratio = -0.64

now in 3rd part magnitude will calculate by subtracting maximum stress - minimum stress i.e.

magnitude = \sigma _{maximum} - \sigma _{minimum}  

magnitude = 275 - (-175) = 450 MPa

3 0
3 years ago
Leland wants to work in a Production career operating heavy machinery. Which type of education or training should Leland seek?
zhenek [66]

Answer:

it is indeed C

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Which solution causes cells to shrink
    13·1 answer
  • 6. Staples are the most common item used to secure and support cables in residential wiring.​
    14·1 answer
  • What is the Principle of Entropy Increase?
    9·1 answer
  • A household refrigerator that has a power input of 450 W and a COP of 1.5 is to cool 5 large watermelons, 10 kg each, to 8 C. If
    7·1 answer
  • From the information generated in Prob. 6.4 (from your previous Aero HW#1), calculate the maximum rate of climb for the single-e
    13·1 answer
  • 37. In ______ combination of drugs, the effects of one drug cancel or diminish
    12·1 answer
  • What should you consider when choosing the type of hearing protection you use?
    15·1 answer
  • What is the purpose of making a jello pool
    6·1 answer
  • 9. A piece of Cherry wood is 5/4 x 4" X 4'<br> What is the length in inches?
    10·1 answer
  • A motor takes 38 amperes on a 220-volt circuit. Find the horsepower output (hp) of the motor shown with an efficiency of 90%. Ex
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!