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
Pls help me thank you ​
sergey [27]

Answer:   1.  Hand Plane

                 2. Rift Sawn

Explanation:  I'm not Sure tho hope it helps

8 0
2 years ago
Read 2 more answers
Student A says used oil filters may be immediately dumped in the trash. Student B says used oil filters must be punctured and dr
pogonyaev
Chupapi munyanyo holaa
7 0
3 years ago
Si la demanda por un bien final es elástica, entonces la demanda de trabajo correspondiente también es elástica
shusha [124]

Answer:

You can speak English to help you

4 0
3 years ago
A steel with 1.0 % carbon is known as which one of the following: (a) eutectoid, (b) hypoeutectoid, (c) hypereutectoid, or (d) w
natta225 [31]

Answer:

Option c)

Explanation:

a.The carbon content of eutectoid steel, which is an carbon- iron alloy, is in between 0.80-0.83%

b. In hypoeutectoid steel, the carbon composition is less than 0.80% and is approximately 0.76%

c. In hypereutectoid steel, the carbon composition ranges from 0.80% - 2.0%

d. In wrought iron, the iron composition is quite low about 0.08%

3 0
3 years ago
A scientist who is evaluating an ancient human skeleton for signs of vitamin and nutrient deficiency is conducting:
lawyer [7]

Answer:

paleopathology

Explanation:

Paleopathology is a relatively new discipline.

Paleopathology is mainly the study of the traces of disease left in fossils and mummies. It also includes the study of the signs related to the disease in archaeological objects.

8 0
3 years ago
Other questions:
  • For all substances, Cp&gt;C. Why is that?
    15·1 answer
  • 1. What types of fire can plain water be used on?
    14·2 answers
  • Consider the following algorithm, which takes as input asequence of n integers a1, a2, . . . , an and produces as outputa matrix
    15·1 answer
  • End A of the uniform 5-kg bar is pinned freely to the collar, which has an acceleration = 4 m/s2 along the fixed horizontal shaf
    9·1 answer
  • What are the desired characteristics or values for the following parameters of an ideal amplifier?o Phase change as a function o
    10·1 answer
  • Tech A says that over time a grease seal can wear a groove in the sealing surface of the axle or shaft. Tech B says that grease
    6·2 answers
  • An adiabatic air compressor compresses 10 L/s of air at 120 kPa and 20 degree C to 1000 kPa and 300 degree C.
    11·1 answer
  • Ughhh my cramps hurt sm
    8·2 answers
  • What is the definition of gross axle weight rating?.
    5·1 answer
  • To avoid carbon monoxide poisoning, use the heater or air conditioner in a parked car with the windows closed.T/F
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!