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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:56:39+00:00 2026-06-03T18:56:39+00:00

#include <string> using namespace std; class PersonList { private: char aName[7]; int aBribe; PersonList

  • 0
#include <string>

using namespace std;

class PersonList
{

private:
    char aName[7];
    int aBribe;
    PersonList *link;

public:
    void addNodes();
    void display();

};

#include <iostream>
#include <string>

using namespace std;

#include "mylink.h"

void PersonList::addNodes()
{

    PersonList *temp2;

    PersonList* startPtr = new PersonList();
    PersonList* current = new PersonList();


        PersonList *temp = new PersonList();//created the first node on the list
        cout<<"Enter the person's name: ";
        cin>>temp->aName;
        cout<<"Enter the person's contribution: ";
        cin>>temp->aBribe;
        temp->link=NULL;//when i get last node, link will point to null(where am i in list?)

        if(startPtr==NULL)
        {
            startPtr = temp;
            current = startPtr;
        }

        else
        {
            temp2 = startPtr;

            while(temp2->link!=NULL)
                temp2 = temp2->link;
            temp2->link=temp;
        }
    //}
}

void PersonList::display()
{
    PersonList *temp;
    PersonList *startPtr = this;

    temp=startPtr;

    while(temp != NULL)
    {
        cout<<temp->aName<<"\t\t"<<temp->aBribe<<endl;
        temp = temp->link;
    }

}

#include <iostream>
#include "mylink.h"

using namespace std;

int displayMenu (void);
void processChoice(int, PersonList&);

int main()
{
int num;

PersonList myList;


do 
{
num = displayMenu();
if (num != 3)
processChoice(num, myList);
} while (num != 3);

return 0;
}

int displayMenu(void)
{
int choice;
cout << "\nMenu\n";
cout << "==============================\n\n";
cout << "1. Add student to waiting list\n";
cout << "2. View waiting list\n";
cout << "3. Exit program\n\n";
cout << "Please enter choice: ";
cin >> choice;

cin.ignore();
return choice;
}

void processChoice(int choice, PersonList& p)
{

switch(choice)
{
case 1: p.addNodes();
break;
case 2: p.display();
break;
}

}

My question is the display function is not displaying name and contribution that I enter.
Im using temp variable as a pointer node to call aName and aBribe. This goes through the list while it has not reached null. Nothing shows in output

  • 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-03T18:56:41+00:00Added an answer on June 3, 2026 at 6:56 pm

    You are creating a new list:

    PersonList *startPtr = new PersonList();
    

    and then showing that. So, naturally it is empty.

    You have a similar problem in your addNodes method. You are adding nodes to a new list, then throwing it away, which is actually a memory leak.

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

Sidebar

Related Questions

#include <iostream> #include <set> using namespace std; class StudentT { public: int id; string
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
#include <stdexcept> #include <string> using namespace std; class ListIndexOutOfRangeException : public out_of_range { public:
#include stdafx.h #include <string> #include <map> using namespace std; class NiftyEmailProgram { private: typedef
#include <iostream> #include <string> using namespace std; class BookData { string Title; int Qty;
In the sample: #include <iostream> using namespace std; class B { public: virtual void
#include <gtk/gtk.h> #include <string> using namespace std; class WIN { protected: GtkWidget *window; public:
#include <iostream> using namespace std; template<class T> void toBinary(T num) { char * numi
I have abstract class: #include <string> using namespace std; class AString { public: virtual
#ifndef MIGRATINGUSER_H #define MIGRATINGUSER_H #include <iostream> using namespace std; class MigratingUser { public: void

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.