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 8456103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:27:39+00:00 2026-06-10T12:27:39+00:00

I need help with something which I believe is simple. I can assign a

  • 0

I need help with something which I believe is simple. I can assign a student to a project. But when I delete the project, the student is still keeping the project name. I’m thinking of just renaming it back to “None” but I have no idea on how to do that. Help?

Edit
map<int, Student> mstore and vector<int> storeid added.

#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
using namespace std;
class Human {
public:
    virtual void print() const = 0;
};

class Student : public Human {
protected:
    string studname;
    int studId;
    string project;
public:

    Student();
    Student (string studname, int studId) : studname("Unknown"), studId(0), project("None") 
    {
        cout << "A student is created: Name = " << studname
         << ". Id = " << studId << endl;
    }

    virtual void print() const {
    cout << "Name = " << studname << ". Id = " << studId << ". Project = " << project <<endl; }

    void setSName (string sname) { studname = sname; }
    void setSID (int sID) { studId = sID; }
    void printStudentInfo() const;
    void printStudentInfoline() const;
};

void Student::printStudentInfo() const
{
    cout << "\nStudent name: " << studname << endl;
    cout << "Student ID: " << studId << endl;
    cout << "Project: " << project << endl;
}

void Student::printStudentInfoline() const
{
    cout << studId << ", " << studname << ", " << project << endl;
}

class Project {
protected:
    string projname;

public:
    vector <Student> students;
    vector <int> storeid;

    Project (string projname) : projname(projname) { cout << "Project " << projname << " created" << endl;}

    void setPName (string projname) { this->projname = projname; }

    void add (int& sid) 
    {
        //student.setProject (projname);
        storeid.push_back(sid);
    }

    int returnid(int& a)
    {   
        return storeid[a]; 
    }

    int returnsize()
    {   return storeid.size(); }

    void printproj() const {
        cout << endl << projname << " list: \n";
        cout << "Student(s) : " << endl;
        for (int i = 0; i < storeid.size(); i++){
            cout << storeid[i] << endl;
        }
    }

    void printprojname() const {
    cout << projname << endl;
    }


};

int main() {
string StudentName;
string ProjectName;

int Studentid;

Student *s1;
Project *p1;

vector<Student> store;
vector<Project> projstore;
map<int, Student> mstore;


map<int, Student>::const_iterator itr;
    for (int n=0; n<3; n++) //loop to create 3 students
   { 
    cout <<"Enter name : ";
    getline(cin, StudentName);
    cout <<"Enter  ID : ";
    cin >> Studentid;

    s1 = new Student(StudentName, Studentid);
    s1->setSName(StudentName);
    s1->setSID(Studentid);
    store.push_back(*s1);
    mstore.insert(make_pair(Studentid, *s1));
    cin.get();
    }
    //print map
    for(itr=mstore.begin(); itr!=mstore.end() ;++itr)
    itr->second.printStudentInfo();

    //itr=mstore.begin()+2;
    //itr.print();




cout << "Enter project name: ";
getline(cin, ProjectName);

p1 = new Project(ProjectName);
p1->setPName(ProjectName);

 //Assigning student to project
    cout << endl;
    cout << "How many students? :" ;

    int y;
    cin >> y;
    for ( int i = 0; i < y; i++){
    cout << "Who would you like to add to this project?" << endl;
    int x = 1;

    for(itr=mstore.begin(); itr!=mstore.end() ;++itr)
    itr->second.printStudentInfoline();

    int insID;
    cout << "Enter ID number: ";
    cin >> insID;
    p1->add(insID);

    /*
    for ( it = store.begin(); it != store.end(); ++it ) {
        // For each friend, print out their info

    cout << x << ". ";
          it->printStudentInfoline();
    x++;

    }
    x = 1;  
    int insS;
    cout << "Enter number: ";
    cin >> insS;
    p1->add(store[(insS-1)]);   //stores selected student into the object
    */

    cout << "\nAdding Student done\n" << endl;
    }
    projstore.push_back(*p1);

    //Mstore finds for related ids and displays them accordingly
cout << "print project"<< endl;
    vector<Project>::iterator pt;
    for ( pt = projstore.begin(); pt != projstore.end(); ++pt ) {
        pt->returnsize();
        for (int i=0; i <pt->returnsize(); i++){
        cout << pt->returnid(i) << endl;

        itr=mstore.find(pt->returnid(i));

        itr->second.printStudentInfo();
        }            
    }


    cout << endl;
    cout << "Deleting project" << endl;
    cout << "What would you like to remove?" << endl;
    int x = 1;

    //storeid will display ids. How do I link them to `store` map?
    for ( pt = projstore.begin(); pt != projstore.end(); ++pt ) {
      cout << x << ". ";
      pt->printprojname();
      x++;
    }


    //Now to delete the selected project
    int delP;
    cout << "Enter number: ";
    cin >> delP;
    cin.ignore();
    system("pause");
    projstore.erase(projstore.begin()+delP-1);

// Students

cout << "\n Current students" << endl;
for(itr=mstore.begin(); itr!=mstore.end() ;++itr)
    itr->second.printStudentInfo();

}
  • 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-06-10T12:27:41+00:00Added an answer on June 10, 2026 at 12:27 pm

    Look at how you add a Student to a Project:

    void add (Student& student)
    {
      student.setProject (projname);
      students.push_back (student);    // <-- AHA!
    }
    

    First you assign the Project name to the Student, then the Project stores a copy of the Student. After that, the Project has no link to the original Student, and can’t inform him/her of its own demise when the time comes.

    You’ll have to rethink this design; there are three major options: 1) the Students can look up their respective Projects in the store, 2) the Project can look up its Students in the students vector, or 3) the Project owns the Students (in which case they should probably be GraduateStudents).

    EDIT:
    If that’s the way you want to do it, use map<int, Student> store to store the Students, using ID number as an index. Then a Project can have a vector<int> (or set<int>) of student ID numbers. It can look Students up in the store with ease.

    EDIT:
    To print out the entire collection of students:

    for(map<int, Student>::const_iterator itr=store.begin(); itr!=store.end() ;++itr)
      itr->second.print();
    

    EDIT:
    If the Project has a vector<int> of student ID numbers, then what argument do you think Project::add(?) should take?

    EDIT:
    The Project can act on a Student by means of the student ID number and access to mstore:

    // in Project:
    mstore[id].whatever()
    

    EDIT:
    Sometimes asking the right question — or in this case, phrasing the question correctly — is half the battle. ‘Now how do I change “None” to the inserted project name?’ A better way to put it is ‘How does the Project change one of its Student’s project from “None” to projname?’ Once you put it that way, the answer is almost obvious:

    // in Project:
    mstore[id].setSProject(projname);
    

    Note that Student does not yet have setSProject(string), you’ll have to add it. Also, note that this solution is not ideal since 1) anybody can change a Student’s project, and 2) a Student’s project need not actually be the name of a real Project. There is more than one way to deal with these problems.

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

Sidebar

Related Questions

I have a practice project which I need help with. It's a simple MailServer
I need some help with something... say I have the following form... <form name=
i need help knowing how to post up a message in mfc project. but
I am trying to implement something which my logic says can't be done. But
Hello i am new in android and i really need help with something. I
I need a little help clearing something up with Zend_Form and adding filters to
I'm really need help with parsing XML by TBXML. I created a demo project
I want to write a simple program which can customize iphone icons like their
I need help figuring out how to accomodate situations in which $hash {$i} is
I need a help with what I believe is very trivial stuff. class User

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.