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
Psychologist who uses behavioral approach to therapy would probably try which of the following
12345 [234]

Answer:

what following

Explanation:

5 0
3 years ago
Read 2 more answers
Go online and search for information about companies that have been harmed or bankrupted by a disaster. Choose one such company
tester [92]

Answer:

See explaination

Explanation:

In recent times and in the past, so many companies have been dealt with or bankrupted by disaster.

This disasters are in the form of floods, earthquake and tsunami. This has led to many companies across world to have faced problem. As Japan is particularly vulnerable to natural disaster because of its climate and topography let me take example of japan .The tsunami that struck Japan in March this year which has lead to a debt of worth nearly $8 billion due to failed businesses. A total of 341 firms in japan with a combined 6,376 employees has got affected by this disaster.

One of company that hit hard by these disaster is Toyota. Toyota is a Japanese multinational automotive manufacturer headquartered in Toyota, Aichi, Japan. Actually due to flood in thailand toyota has faced a big loss. As flood hit thailand the parts of vehicle which is produced in thailand has stopped . It leads to interruption in the supply chain of some Thailand made components.

This lead to suspension of production as thai made component was unavailable.It has been reported until the situation of thailand will be good toyota plants in Indiana, Kentucky and Ontario, Canada, will be shut down . And production rate at plant in North America will get slow down .This flood leads to a loss of 37500 vehicles .Due to this reason toyota was forced to open its plants in Southeast asian country just to enhance the production rate.Sales of vehicle has also got reduced in thailand . Hence toyota faced a total loss of 1.6 billion dollar.

In Nigeria, due to the insurgency of the Boko Haram, many companies have entirely stopped operations in some regions, this harsh realities leads to massive loss of revenue for such companies.

3 0
3 years ago
The basic concept of feedback control is that an error must exist before some corrective action can be made?
weqwewe [10]

Answer:

The correct answer is True.

Explanation:

The feedback control system implies that to make a feedback, there must first be an error, otherwise there will be nothing to correct.

This system works so that there is an output that is controlled through a signal.

This signal will be feedback and it will signal an error which will be detected by a controller that will allow entry into the system.

In basic words, this system processes signals, samples them in the form of an output, and re-enters them feedback to detect the error signal.  

7 0
3 years ago
PLEASE HELP 100 POINTS!!! WILL MARK BRAINLIEST
OlgaM077 [116]
Business plan, a good strategy to help pin point the house best fetchers
5 0
3 years ago
Read 2 more answers
All circuits need three basic parts: an energy source, wires, and the object that is going to change the electrical energy into
Radda [10]

load every electric circuit,regardless of where it is or how large or small, has four basic parts: an energy source (ac or dc),a conductor (wire), an electrical load (device), and at least one controller(switch)
7 0
3 years ago
Read 2 more answers
Other questions:
  • The function of a circuit breaker is to _____.
    12·1 answer
  • A groundwater contains the following cations (expressed as the cation):
    5·2 answers
  • The steel bar has a 20 x 10 mm rectangular cross section and is welded along section a-a. The weld material has a tensile yield
    11·1 answer
  • The slope of a moment diagram is the load. a)-True b)-False
    8·1 answer
  • Consider an InSb NW with ballistic mean free path of 150nm. Calculate the current through a 250nm long InSb NW when a 100mV bias
    6·1 answer
  • ________ is the most theoretical computing discipline, focusing mostly on finding new and better ways for computers to work
    9·1 answer
  • Question 3. Assign boston_under_10 and manila_under_10 to the percentage of rides that are less than 10 minutes in their respect
    14·1 answer
  • What word is typically written at the bottom of a cover letter to indicate an
    12·2 answers
  • If 3 varies inversely as x and y=2 when x=25, find x when y=40
    7·1 answer
  • Our aim is to calculate the efficiency of a gas turbine by assuming it operation can be modeled as a Carnot cycle. The kerosene
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!