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]
4 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]4 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
A stem and leaf display
Crank
5/2055 classes displayed there’s Nooooob changes
3 0
3 years ago
Which regulations are related to guard rail height and dimensions and uniformity of stairs?
galina1969 [7]

Answer:

C.

structural safety

Explanation:

Guards protecting floor surfaces must be 36 inches in height, while guards for stairs must be 34 inches in height measured vertically from the tread nosing. A guard may also serve as the required handrail (34 to 38 inches high) provided the top rail meets the requirements for grip size.

4 0
3 years ago
Read 2 more answers
A __________ is a single lane used by drivers to enter and exit a freeway. a) Climbing lane b) Weave lane c) Thru lane d) Offset
Rufina [12.5K]

A Weave lane is a single lane used by drivers to enter and exit a freeway.

<h3>What is this lane about?</h3>

Weave lanes are known to be lanes that acts as an entrance and exits for a lot of cars in highways.

Hence, one can say that A Weave lane is a single lane used by drivers to enter and exit a freeway.

Learn more about Weave lane from

brainly.com/question/10828527

#SPJ1

6 0
2 years ago
For the system form of the basic laws, the momentum of a system can change as a result of: a. pressure acting on the system. b.
Ymorist [56]

Answer: F. All the above.

Explanation:

Basically, if an object is moving, it moves with a certain velocity and mass. Momentum of a body is a product of mass and velocity. The sum of momentum of individual bodies is equal to the entire system momentum. For instance, a block v is moving due to an applied force F, with a velocity V and the gravity g. Due to gravity, the weight is mg. Due to gravity, the weight is acting downward. Applied force is acting on the block surface area A.

Pressure = Surface force/Surface area.

Surface force is acting on the surface applied. So, acting pressure = Force applied/area.

Pressure and surface force is acting on the body. Body forces also act on the system. Forces due to gravity is also referred to as body force. As a result of weight of the box, Normal force produced by the rough surface is equal to the Weight. As a result of rough surface, frictional forces are produced which opposes the block to move forward. All the external forces create a net total force due to which the block move with a velocity and acceleration.

In Newton's second law, Ftotal is equal to mass × acceleration.

Therefore, we can conclude that momentum can change as a result of all these forces because mass × acceleration is related to total force and momentum is equal to mass × velocity.

7 0
3 years ago
Read 2 more answers
You read a research study that concludes that the higher a student's self-esteem, the better he performs in school. This sort of
LiRa [457]

Answer:

Negative correlation

7 0
4 years ago
Other questions:
  • .The war of the currents in the 1880's involved Thomas Edison and Nikola Tesla on a reality TV show stranded on an island. Each
    9·1 answer
  • 3. Consider a 10-m-long smooth rectangular tube, with a = 50 mm and b=25 mm, that is maintained at a constant surface temperatur
    5·1 answer
  • Convert
    6·1 answer
  • Which timeline shows the correct order of contributions made to the discovery of DNA?
    6·2 answers
  • There are three MUXes in the EX stage. Among them, the 2 MUXes located at the top is meant to provide correct ALU source data 1
    13·1 answer
  • Water enters a centrifugal pump axially at atmospheric pressure at a rate of 0.12 m3
    10·1 answer
  • One of the personality traits listed for a cement mason is attention to detail.
    11·1 answer
  • B/ Evaluate e^(πi/2)
    9·2 answers
  • The __________________ refers to the main screen of the computer.
    9·1 answer
  • What are the horizontal structures beneath a slab that help transfer the load from the slab to the columns?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!