Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:56:18+00:00 2026-05-28T19:56:18+00:00

I worked on this all day and am stuck on my logic in how

  • 0

I worked on this all day and am stuck on my logic in how I approached this problem. Whenever I have a Vector<class> blah. And I try to blah.push_back(class()), it doesn’t, update or work.

I’ve been researching and I think it has to do with pointers and references. I tried changing Vector<Student> blah to Vector<Student*> blah, and using ‘new’ Student() when I’m pushing it back, but it still yields the same result. I think I’m defining the vectors wrong.

#include "std_lib_facilities.h"
using namespace std;

class Student
{
  public:
    string first_name;
    string last_name;
    string major;
    int student_id;

    Student() {};

    Student(int no, string name1, string name2, string majorin)
    {
      first_name = name1;
      last_name = name2;
      student_id = no;
      major = majorin;
    }

};

class Course
{
  public:
    Vector<Student> Students;
    int max_enrollment;
    int course_id;
    string course_title;

    Course() {};

    Course(int no_in,int max_in,string title_in)
    {
      max_enrollment=max_in;
      course_title=title_in;
      course_id=no_in;
    }

};

unsigned int split(const std::string &txt, vector<std::string> &strs, char ch)
{
  unsigned int pos = txt.find( ch );
  unsigned int initialPos = 0;
  strs.clear();

  // Decompose statement
  while( pos != std::string::npos ) {
    strs.push_back( txt.substr( initialPos, pos - initialPos + 1 ) );
    initialPos = pos + 1;

    pos = txt.find( ch, initialPos );
  }

  // Add the last one
  strs.push_back( txt.substr( initialPos, std::min( pos, txt.size() ) - initialPos + 1 ) );

  return strs.size();
}

class University
{
  public:
    Vector<Student> studentlist;
    Vector<Course> courselist;

    University() {};

  void Parse(string input)
  {
    //Case Statements
    vector<string> temp;
    split( input, temp, ' ' );
    cout<<temp[0];
    if (temp[0]=="S ")
    {
      //Add Student to University
      //Student* myStudent=new );
      cout<<studentlist.size()<<endl;
      //Student(atoi(temp[1].c_str()),temp[2],temp[3],temp[4])
      studentlist.push_back(Student()); 
    }
    else if (temp[0]=="C")
    {
      //Add Course to University
      Course myCourse=Course(atoi(temp[1].c_str()),atoi(temp[2].c_str()),temp[3]);
      courselist.push_back(myCourse);
    }
    else if (temp[0]=="L")
    {
      //Add Student to Course list
      //Not Implemented-Find Course by temp[1] which is a int
      for (int i=0;i<courselist.size();i++)
      {
        if (courselist.at(i).course_id==atoi(temp[1].c_str()))
        {
          courselist.at(i).max_enrollment=atoi(temp[1].c_str());
        }
      }
    }
    else if (temp[0]=="A")
    {
      for (int i=0;i<courselist.size();i++)
      {
        if (courselist.at(i).course_id==atoi(temp[1].c_str()))
        {
          for (int j=0;j<studentlist.size();j++)
          {
            if (studentlist.at(j).student_id==atoi(temp[1].c_str()))
        {
          Student mystudent=studentlist.at(j);
          courselist.at(i).Students.push_back(mystudent);
        }
          }
        }
      }
    }
    else if (temp[0]=="D")
    {
      for (int i=0;i<courselist.size();i++)
      {
        if (courselist.at(i).course_id==atoi(temp[1].c_str()))
        {
          for (int j=0;j<courselist.at(i).Students.size();j++)
          {
            if (courselist.at(i).Students.at(j).student_id==atoi(temp[1].c_str()))
            {
              //Student mystudent=courselist.at(i).Students.at(j);
          courselist.at(i).Students.erase(courselist.at(i).Students.begin()+j);
            }
          }
        }
      }
    }
    else if (temp[0]=="PS")
    {
      cout<<"--Student Report--\n";
    }
    else if (temp[0]=="PC")
    {
      cout<<"--Student Report--\n";
      for (int i=0;i<courselist.size();i++)
      {
        for (int j=0;j<courselist.at(i).Students.size();j++)
        {
          string first_name=courselist.at(i).Students.at(j).first_name;
          string last_name=courselist.at(i).Students.at(j).last_name;
          string major=courselist.at(i).Students.at(j).major;
          //Waiting List var
          cout<<first_name<<" "<<last_name<<" "<<major<<"\n";
        }
      }
    }
  }
};

int main(int argc, char *argv[])
{
  string input;
  while(1==1)
  {
    cout<<"Command:: ";
    getline(cin,input);
    //cout<<input;

    University myUniversity;
    myUniversity.Parse(input); //Input is in the format X Name Name etc etc. Arguments separated by spaces
    cout<<"DEBUG:"<<myUniversity.studentlist.size();
  }
  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:56:19+00:00Added an answer on May 28, 2026 at 7:56 pm

    Simple Error! Can’t believe you spent so long on this! Haha.

    You defined your University inside your while loop!

    I’m not familiar with C++ (learning myself), but I think it should also be done using pointers and references and the keyword ‘new’.

    Can someone explain the difference between the way he’s doing it and other ways I’ve seen where people use Student mystudent=new Student(); etc etc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have worked on this problem for my entire day and can't solve it.
Possible Duplicate: Weird “406 not acceptable” error I've been stuck on this ALL DAY!
I have a problem with JNI that has taken me all day and will
This all worked fine in rails 2.3.5, but when a contractor firm upgraded directly
At the beginning this worked fine: $ rake cucumber:all But then $ script/plugin install
I was under the impression all this time that .on() worked like .live() with
I have come across Evernote's bookmarklet and was wondering how this worked. You can
I've been searching all day and found several similar issues, but none have resolved
Good day all; I am not sure what has changed to prevent this from
I'm gonna try and simplify this as much as possible. Lets say i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.