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
Una empresa realizó en el ejercicio de compras al contado por valor
Tanzania [10]

Answer:

englishhhh pleasee

Explanation:

we dont understand sorry....

8 0
3 years ago
What is the magnetic force on a moving electric charge called
crimeas [40]
The magnetic force on a free moving charge is perpendicular to both the velocity of the charge and the magnetic field with direction given by the right hand rule. The force is given by the charge times the vector product of velocity and magnetic field.
4 0
3 years ago
Read 2 more answers
A hypothetical metal alloy has a grain diameter of 2.4 × 10−2 mm. After a heat treatment at 575°C for 500 min, the grain diamete
Alex

Answer:

The time required is 10.078 hours or 605 min

Explanation:

The formula to apply here is ;

K=(d²-d²₀ )/t

where t is time in hours

d is grain diameter to be achieved after heating in mm

d₀ is the grain diameter before heating in mm

Given

d=5.5 × 10^-2 mm

d₀=2.4 × 10^-2 mm

t₁= 500 min = 500/60 =25/3 hrs

t₂=?

n=2.2

First find K

K=(d²-d²₀ )/t₁

K={ (5.1 × 10^-2 mm)²-(2.4 × 10−2 mm)² }/ 25/3

K=(0.051²-0.024²) ÷25/2

K=0.000243 mm²/h

Re-arrange equation for K ,to get the equation for d as;

d=√(d₀²+ Kt)  where now t=t₂

d=\sqrt{0.024^2+0.000243*t} \\\\0.055=\sqrt{0.024^2+0.000243t} \\\\0.055^2=0.024^2+0.000243t\\\\0.055^2-0.024^2=0.000243t\\\\0.002449=0.000243t\\\\0.002449/0.000243=t\\\\10.078=t\\\\t=605min

4 0
3 years ago
Aaron needs to create a building design for a restaurant with colors that depict excitement and vibrancy. Which color can Aaron
zloy xaker [14]

Answer:

I'm no engineer, but blue and purple are cool colors and white is every color so I'd go with orange

7 0
3 years ago
Read 2 more answers
Calculate the torque produced by a motor that has 500 windings across a 30cm diameter rotating core. The core is 0.6 M long insi
zalisa [80]

Answer:

hhjhfdddvhyyjjvfrryjjbcdryuj vdryujbcr4yug

7 0
3 years ago
Other questions:
  • Tadpoles raised in water with atrazine levels of 0.1 ppb should produce a higher percentage of male frogs with gonadal abnormali
    13·1 answer
  • The air in a room has a pressure of 1 atm, a dry-bulb temperature of 24C, and a wet-bulb temperature of 17C. Using the psychrome
    12·1 answer
  • Which factors influence changes in consumer demands? check all that apply
    8·2 answers
  • Design complementary static CMOS circuits with minimized number of transistors to realize the following Boolean functions (hint:
    13·1 answer
  • This app, I'm done, bye... I can't, bye
    11·1 answer
  • Giving away free brainliest your welcome​
    15·2 answers
  • PLEASE HELP ME RIGHT NOW!!
    11·1 answer
  • Which of the following is true regarding screw gauges and shank?
    5·1 answer
  • ¿Por qué la lógica de proposiciones es conocida también como lógica de las proposiciones sin analizar?
    11·1 answer
  • A school bus with its flashing red signals on has stopped on a non-divided highway; you must?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!