Issue with how to properly use push_front and pop_front.

I have a class named
Account

I am suppose to be able to be able to add new accounts and new balances but I can't find the proper documentation on how to do this. I am trying to figure out what do I put in my header file in the class declaration, what to put in the .cpp file and what to put in the main.cpp file.

Below are some excerpts from my code,

//Header file
#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <string>
using namespace std;

class account
{
public:
//default constructor
account();

//constructors
account(string, double);
//Account - Sets up an account given an account number
// with zero balance.
//@param int - The account number.

void setName(string);
void setBalance(double);

/***********************.cpp file
#include "account.h"

#include <iostream>

account::account()
{
accountName = "";
balance = 0.0;
}

account::account(string newAccountName, double newBalance)
{
accountName = newAccountName;
balance = newBalance;
}


void account::setName(string newAccountName)
{
accountName = newAccountName;
}

void account::setBalance(double newBalance)
{
balance = newBalance;
}

string balance::getName() const
{
return accountName;
}

/************ main.cpp file

#include "account.h"

#include <iostream>
#include <list>
using namespace std;

int main()
{
string name;
double balance;
cout << "***************************************…
<< "\tAccount Class Tester\n"
<< "***************************************…

//Create an account for Bob Peterson.
//Bob has no initial balance.
account accountList ("Bob", 111);




cout << "Enter the account's name\n";
cin >> name;
accountList.setName(name);
cout << "New name: " << accountList.getName();

cout << "\n\nEnter the account's balance\n";
cin >> balance;
accountList.setBalance(balance);
cout << "New balance: " << accountList.getBalance();


*******************************

So right now I have the user enter in the information but what I suppose to do is to use the following list objects
push_front
pop_front
front

The issue I am running into is I don't know how to properly declare these within the class declaration, .cpp file and main.cpp file Any help would be great. Thanks

Are you supposed to implement your own list class?

Thats the part that I am confused on. First is the word "list" a reserved word? second on cplusplus.com it shows it as

list<int> mylist (2,100); // two ints with a value of 100
mylist.push_front (200);
mylist.push_front (300);

would I change the word list in above code to account? I am totally confused on what to put where and I can't find a decent explanation.

Yes If you are allowed to use STL's list, then list<account> listOfAccounts will do

So right now I have the user enter in the information but what I suppose to do is to use the following list objects
push_front
pop_front
front

Above are the methods on STL, So when you ask about their usage. You first need to understand generic STL's like List , Vector etc..
On that you can call following methods :
push_front //when even you want to push information.
pop_front //when you want to retrieve information.
front //when you want to move to front of data structure.


So firstperson is very right, list is a container and object can be stored into it, In you case it is account.

See this is the part that I am confused on. Currently I have in the main.cpp file

account accountList ("Bob", 111);

would I change this to

list<account> listOfAccounts

or would I add

list<account> listOfAccounts

in addition to what I currently have? If I add it in addition to what I currently have then I am to assume that because it has <account> in it that it has access to the account class? Also how would I go about using push_front and pop_front with this new code to ask the user to enter an account name?

Thanks for the help so far.

tajendra, I understand what the function do but the issue I am running into is the proper format on how to use them. For instance if I want to add an account name would I put

accountList.push_front (name);

or would I use the code that firstPerson used

listOfAccounts.push_front (name);

Add list<account> listOfAccounts to your code.
And create object of account separately, then take input from the user.
After taking the input set it in object of account i.e. in accountList (as per your code).
After that add this to list , listofAccounts.push_front(accountList);

By doing that you will get one new member in your list<account>
Keep on doing same for other new users.

When you want to retrieve the account details then call pop_front() on list.

Tajendra, you just answered my question perfectly. I can't thank you enough. firstPerson thanks for pointing me in the right direction. I do have one more question which has nothing to do with this question though, should I start a new thread? I am going to ask it but if someone wants me to start a new thread I will move it. Here goes

If I have a vector of structs

struct widgets
    {
        string widgetName;
        int age;
        int color;
    };

and widgetName had multiple words in lets say

widget one type
45
blue
widget two
34
yellow
widget eight
46
green
widget ten type
33
pink

and I wanted to search the vector where this information is stored.

vector<widgets> widgetTypes;

Now what I want to do is search through the vector and only find the widgets with the word "type" in it then I want to compare the widgets that have "type" in it and see which one has the highest age. Then I want to output that widget i.e. the widget with the highest age is "widget one type" with an age of "45"?

I know I should use a find and probably npos but kind of unsure if I am right and how to set up the code.

Mark this thread as solved , and start a fresh discussion on it.
It will help all new poster to get the context right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.