c++ issues

must make several headers with inheratance and composition.

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 3482 Views - Last Post: 30 September 2010 - 12:37 PM Rate Topic: -----

#1 Guest_BlueFish*


Reputation:

c++ issues

Posted 29 September 2010 - 06:59 AM

hi, so what my issue is, is that i have several classes and headers and a main that i have to make implementations for in order to make the main work. the problem is that im not sure how to store the data because i think it uses one of the given headers filled with templates, ill give the file to show you what i mean. but the overall assignment must have.
addressType stores street,city,and zip.
extpersontype which inherits from persontype and has composition with dateType and addressType.
addressBookType derived from arrayListType that can store objects of extpersontype. and should be able to load data into functions that are layed out in the header file.
i know this seems like a lot but iv been working at it for a week and somehow i just cant think what to do so a step in the right direction on any section would be more than awesome thanks.

aforementioned code....
#ifndef H_addressBookType
#define H_addressBookType

#include <string>
#include <fstream>
#include "extPersonType.h"
#include "arrayListType.h"

using namespace std;

class addressBookType: public arrayListType<extPersonType>
{
public:
    void print() const;

    void printNameInTheMonth(int month);
    void printInfoOf(string lName);
    void printNamesWithStatus(string status);
    void printAt(int i);

    void printNamesBetweenLastNames(string last1, string last2);

    int search(string lName);

    void saveData(ofstream&);

    addressBookType();
};
    void addressBookType::print() const
    {

    };
    void addressBookType::printNameInTheMonth(int month)
    {
    };
    void addressBookType::printInfoOf(string lName)
    {
    };
    void addressBookType::printNamesWithStatus(string status)
        {
    };
    void addressBookType::printAt(int i)
        {
    };

    void addressBookType::printNamesBetweenLastNames(string last1, string last2)
        {
    };

    int addressBookType::search(string lName)
        {
            arrayListType atemp;
            atemp.seqSearch(lName);
    };

    void addressBookType::saveData(ofstream&)
        {
    };

    addressBookType::addressBookType()
        {
    };

#endif

#ifndef H_addressType
#define H_addressType

#include <string>
#include <fstream>
#include <iostream>

using namespace std;

class addressType
{
public:
void getAddress(string street, string city, string zip);
     addressType();
private:
    string streetname;
    string cityname;
    string statename;
    string zipname;
};
addressType::addressType()
{
string streetname="";
string cityname="";
string statename="";
string zipname="";
};

void addressType::getAddress(string street,string city, string zip)
{
    streetname=street;
    cityname=city;
    zipname=zip;
};
#endif

#ifndef H_arrayListType
#define H_arrayListType

#include <iostream>
#include <cassert>

using namespace std;

template <class elemType>
class arrayListType
{
public:
    const arrayListType<elemType>& operator=
                         (const arrayListType<elemType>&);
      //Overloads the assignment operator
    bool isEmpty() const;
      //Function to determine whether the list is empty
      //Postcondition: Returns true if the list is empty; 
      //    otherwise, returns false.
    bool isFull() const;
      //Function to determine whether the list is full.
      //Postcondition: Returns true if the list is full; 
      //    otherwise, returns false.
    int listSize() const;
      //Function to determine the number of elements in the list
      //Postcondition: Returns the value of length.
    int maxListSize() const;
      //Function to determine the size of the list.
      //Postcondition: Returns the value of maxSize.
    void print() const;
      //Function to output the elements of the list
      //Postcondition: Elements of the list are output on the 
       //   standard output device.
    bool isItemAtEqual(int location, const elemType& item) const;
      //Function to determine whether the item is the same 
      //as the item in the list at the position specified by
      //Postcondition: Returns true if the list[location] 
      //    is the same as the item; otherwise, 
      //               returns false.
   void insertAt(int location, const elemType& insertItem);
      //Function to insert an item in the list at the 
      //position specified by location. The item to be inserted 
      //is passed as a parameter to the function.
      //Postcondition: Starting at location, the elements of the
      //    list are shifted down, list[location] = insertItem;,
      //    and length++;. If the list is full or location is
      //    out of range, an appropriate message is displayed.
   void insertEnd(const elemType& insertItem);
      //Function to insert an item at the end of the list. 
      //The parameter insertItem specifies the item to be inserted.
      //Postcondition: list[length] = insertItem; and length++;
      //    If the list is full, an appropriate message is 
      //    displayed.
    void removeAt(int location);
      //Function to remove the item from the list at the 
      //position specified by location 
      //Postcondition: The list element at list[location] is removed
      //    and length is decremented by 1. If location is out of 
      //    range,an appropriate message is displayed.
    void retrieveAt(int location, elemType& retItem) const;
      //Function to retrieve the element from the list at the  
      //position specified by location. 
      //Postcondition: retItem = list[location] 
      //    If location is out of range, an appropriate message is
      //    displayed.
    void replaceAt(int location, const elemType& repItem);
      //Function to replace the elements in the list at the 
      //position specified by location. The item to be replaced 
      //is specified by the parameter repItem.
      //Postcondition: list[location] = repItem 
      //    If location is out of range, an appropriate message is
      //    displayed.
    void clearList();
      //Function to remove all the elements from the list. 
      //After this operation, the size of the list is zero.
      //Postcondition: length = 0;
    int seqSearch(const elemType& item) const;
      //Function to search the list for a given item. 
      //Postcondition: If the item is found, returns the location 
      //    in the array where the item is found; otherwise,
      //    returns -1.
    void insert(const elemType& insertItem);
      //Function to insert the item specified by the parameter 
      //insertItem at the end of the list. However, first the
      //list is searched to see whether the item to be inserted 
      //is already in the list. 
      //Postcondition: list[length] = insertItem and length++
      //     If the item is already in the list or the list
      //     is full, an appropriate message is displayed.
    void remove(const elemType& removeItem);
      //Function to remove an item from the list. The parameter 
      //removeItem specifies the item to be removed.
      //Postcondition: If removeItem is found in the list,
      //      it is removed from the list and length is 
      //      decremented by one.

    arrayListType(int size = 100);
      //constructor
      //Creates an array of the size specified by the 
      //parameter size. The default array size is 100.
      //Postcondition: The list points to the array, length = 0, 
      //    and maxSize = size
    
    arrayListType(const arrayListType<elemType>& otherList); 
      //copy constructor

    ~arrayListType();
      //destructor
      //Deallocates the memory occupied by the array.

protected:
    elemType *list;  //array to hold the list elements
    int length;      //to store the length of the list
    int maxSize;     //to store the maximum size of the list
};

template <class elemType>
bool arrayListType<elemType>::isEmpty() const
{
    return (length == 0);
}

template <class elemType>
bool arrayListType<elemType>::isFull() const
{
    return (length == maxSize);
}

template <class elemType>
int arrayListType<elemType>::listSize() const
{
    return length;
}

template <class elemType>
int arrayListType<elemType>::maxListSize() const
{
    return maxSize;
}

template <class elemType>
void arrayListType<elemType>::print() const
{
    for (int i = 0; i < length; i++)
        cout << list[i] << " ";

    cout << endl;
}

template <class elemType>
bool arrayListType<elemType>::isItemAtEqual
                            (int location, const elemType& item) const
{
    return (list[location] == item);
}

template <class elemType>
void arrayListType<elemType>::insertAt
                  (int location, const elemType& insertItem)
{
    if (location < 0 || location >= maxSize)
        cerr << "The position of the item to be inserted "
             << "is out of range" << endl;
    else
        if (length >= maxSize)  //list is full
            cerr << "Cannot insert in a full list" << endl;
        else
        {
            for (int i = length; i > location; i--)
                 list[i] = list[i - 1];   //move the elements down

            list[location] = insertItem;  //insert the item at the 
                                          //specified position

            length++;     //increment the length
    }
} //end insertAt

template <class elemType>
void arrayListType<elemType>::insertEnd(const elemType& insertItem)
{

    if (length >= maxSize)  //the list is full
        cerr << "Cannot insert in a full list" << endl;
    else
    {
         list[length] = insertItem;   //insert the item at the end
         length++;   //increment the length
    }
} //end insertEnd

template <class elemType>
void arrayListType<elemType>::removeAt(int location)
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be removed "
             << "is out of range" << endl;
    else
    {
        for (int i = location; i < length - 1; i++)
            list[i] = list[i+1];

        length--;
    }
} //end removeAt

template <class elemType>
void arrayListType<elemType>::retrieveAt
                             (int location, elemType& retItem) const
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be retrieved is "
             << "out of range." << endl;
    else
        retItem = list[location];
} //end retrieveAt


template <class elemType>
void arrayListType<elemType>::replaceAt
                          (int location, const elemType& repItem)
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be replaced is "
             << "out of range." << endl;
    else
        list[location] = repItem;

} //end replaceAt

template <class elemType>
void arrayListType<elemType>::clearList()
{
    length = 0;
} //end clearList

template <class elemType>
int arrayListType<elemType>::seqSearch(const elemType& item) const
{
    int loc;
    bool found = false;

    for (loc = 0; loc < length; loc++)
        if (list[loc] == item)
        {
            found = true;
            break;
        }

    if (found)
        return loc;
    else
        return -1;
} //end seqSearch

template <class elemType>
void arrayListType<elemType>::insert(const elemType& insertItem)
{
    int loc;

    if (length == 0)   //list is empty
        list[length++] = insertItem;    //insert the item and 
                                //increment the length
    else if (length == maxSize)
        cerr << "Cannot insert in a full list." << endl;
    else
    {
        loc = seqSearch(insertItem);

        if (loc == -1)    //the item to be inserted 
                          //does not exist in the list
            list[length++] = insertItem;
        else
            cerr << "the item to be inserted is already in "
                 << "the list. No duplicates are allowed." << endl;
    }
} //end insert

template<class elemType>
void arrayListType<elemType>::remove(const elemType& removeItem)
{
    int loc;

    if (length == 0)
        cerr << "Cannot delete from an empty list." << endl;
    else
    {
        loc = seqSearch(removeItem);

        if (loc != -1)
            removeAt(loc);
        else
            cout << "The item to be deleted is not in the list."
                 << endl;
    }
} //end remove

template <class elemType>
arrayListType<elemType>::arrayListType(int size)
{
    if (size < 0)
    {
        cerr << "The array size must be positive. Creating "
             << "an array of size 100. " << endl;

        maxSize = 100;
    }
    else
        maxSize = size;

    length = 0;

    list = new elemType[maxSize];
    assert(list != NULL);
}

template <class elemType>
arrayListType<elemType>::~arrayListType()
{
    delete [] list;
}


template <class elemType>
arrayListType<elemType>::arrayListType
                   (const arrayListType<elemType>& otherList)
{
    maxSize = otherList.maxSize;
    length = otherList.length;
    list = new elemType[maxSize]; //create the array
    assert(list != NULL);         //terminate if unable to allocate
                                  //memory space

    for (int j = 0; j < length; j++)  //copy otherList
        list [j] = otherList.list[j];
} //end copy constructor

template <class elemType>
const arrayListType<elemType>& arrayListType<elemType>::operator=
                      (const arrayListType<elemType>& otherList)
{
    if (this != &otherList)   //avoid self-assignment
    {
        delete [] list; 
        maxSize = otherList.maxSize; 
        length = otherList.length; 
 
        list = new elemType[maxSize];  //create the array
        assert(list != NULL);   //if unable to allocate memory 
                                //space, terminate the program 
        for (int i = 0; i < length; i++)
            list[i] = otherList.list[i]; 
    }

    return *this; 
}


#endif


#ifndef H_personType
#define H_personType


#include <string>

using namespace std;

class personType
{
public:
    void print() const;
      //Function to output the first name and last name
      //in the form firstName lastName.
  
    void setName(string first, string last);
      //Function to set firstName and lastName according to the
      //parameters.
      //Postcondition: firstName = first; lastName = last

    string getFirstName() const;
      //Function to return the first name.
      //Postcondition: The value of firstName is returned.

    string getLastName() const;
      //Function to return the last name.
      //Postcondition: The value of lastName is returned.

    personType();
      //Default constructor
      //Sets firstName and lastName to null strings.
      //Postcondition: firstName = ""; lastName = "";

    personType(string first, string last);
      //Constructor with parameters.
      //Sets firstName and lastName according to the parameters.
      //Postcondition: firstName = first; lastName = last;  

private:
    string firstName; //variable to store the first name
    string lastName;  //variable to store the last name
};
void personType::print() const
{
    cout << firstName << " " << lastName;
}

void personType::setName(string first, string last)
{
    firstName = first;
    lastName = last;
}

string personType::getFirstName() const
{
    return firstName;
}

string personType::getLastName() const
{
    return lastName;
}

    //Default constructor
personType::personType() 
{ 
    firstName = "";
    lastName = "";
}

    //Constructor with parameters
personType::personType(string first, string last) 
{ 
    firstName = first;
    lastName = last;
}

#endif

#ifndef H_extPersonType
#define H_extPersonType

#include <iostream>
#include <string>
#include "personType.h"
#include "addressType.h"
#include "dateType.h"
#include "arrayListType.h"

using namespace std;

class extPersonType: public personType
{
public:
void setInfo(string first,string last,int month,int day,int year,string street,string city,string state,string zip,string phone,string pStatus);
void print();
void getphonestatus(string phone,string status);
extPersonType();
private:
string Status;
string phonenum;
arrayListType <int>listType;
};
void extPersonType::setInfo(string first,string last,int month,int day,int year,string street,string city,string state,string zip,string phone,string pStatus)
{
    addressType atemp;
    dateType dtemp;
    setName(first,last);
    atemp.getAddress(street,city,zip);
    dtemp.setDate(month,day,year);

};
void extPersonType::getphonestatus(string phone,string pStatus)
{
    phonenum=phone;
    Status=pStatus;
};

#endif

#ifndef date_H
#define date_H

class dateType
{
public:
    void setDate(int month, int day, int year);
      //Function to set the date.
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters.
      //Postcondition: dMonth = month; dDay = day; dYear = year

    int getDay() const;
      //Function to return the day.
      //Postcondition: The value of dDay is returned.

    int getMonth() const;
      //Function to return the month.  
      //Postcondition: The value of dMonth is returned.

    int getYear() const;
      //Function to return the year.     
      //Postcondition: The value of dYear is returned.

    void printDate() const;
      //Function to output the date in the form mm-dd-yyyy.

    dateType(int month = 1, int day = 1, int year = 1900);
      //Constructor to set the date
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters.
      //Postcondition: dMonth = month; dDay = day; dYear = year. If
      //    no values are specified, the default values are used to
      //    initialize the member variables.

private:
    int dMonth; //variable to store the month
    int dDay;   //variable to store the day
    int dYear;  //variable to store the year
};
void dateType::setDate(int month, int day, int year)
{
    dMonth = month;
    dDay = day;
    dYear = year;
}

int dateType::getDay() const 
{
    return dDay;
}

int dateType::getMonth() const 
{
    return dMonth;
}

int dateType::getYear() const 
{
    return dYear;
}

void dateType::printDate() const
{
    cout << dMonth << "-" << dDay << "-" << dYear;
}

    //Constructor with parameters
dateType::dateType(int month, int day, int year) 
{ 
    setDate(month, day, year);
}


#endif


Is This A Good Question/Topic? 0

Replies To: c++ issues

#2 Black_list  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 10

Re: c++ issues

Posted 29 September 2010 - 10:17 AM

So i was given an assignment to make a program based on this main and i was wondering if i could get maybe pointed in the right direction on how to set up the setinfo member because the way its worded seems odd to me, wouldn't temp have to be temp[] for this to work to begin with? thx.

#include <iostream>
#include <fstream>
#include <string>
#include "addressBookType.h"

using namespace std;

void loadAddressBook(addressBookType& adBook);
void saveData(addressBookType& adBook);

void showMenu();

int main()
{
    addressBookType addressBook;
    string str;
    string str1;
    string str2;
    int choice;
    int loc;
    int month;

    loadAddressBook(addressBook);

    showMenu();

    cin >> choice;
    while (choice != 9)
    {
        switch (choice)
        {
        case 1: 
            cout << "Enter the last name of the person: ";
            cin >> str;
            cout << endl;

            loc = addressBook.search(str);

            if (loc != -1)
                cout << str << " is in the address book" << endl;
            else
                cout << str << " is not in the address book" << endl;
            break;
        case 2: 
            cout << "Enter the last name of the person: ";
            cin >> str;
            cout << endl;

            loc = addressBook.search(str);

            if (loc != -1)
                addressBook.printAt(loc);
            else
                cout << str << " is not in the address book" << endl;
            break;
        case 3: 
            cout << "Enter the month number: ";
            cin >> month;
            cout << endl;

            addressBook.printNameInTheMonth(month);
            break;
        case 4: 
            cout << "Enter starting last name: ";
            cin >> str1;
            cout << endl;
            cout << "Enter ending last name: ";
            cin >> str2;
            cout << endl;

            addressBook.printNamesBetweenLastNames(str1, str2);
            break;
        case 5: 
            cout << "Enter person type Family, Friend, Business: ";
            cin >> str;
            cout << endl;

            addressBook.printNamesWithStatus(str);
            break;
        case 6: 
            addressBook.print();
            break;
        case 7: 
            saveData(addressBook);
            break;
        default: 
            cout << "Invalid choice" << endl;
        }

        showMenu();
        cin >> choice;
    }

    char response;

    cout << "Save data Yes (Y/y) No(N/n)?: ";
    cin >> response;
    cout << endl;
    if (response == 'y' || response == 'Y')
        saveData(addressBook);
        
    return 0;
}

void loadAddressBook(addressBookType& adBook)
{
    ifstream infile;

    char filename[50];
    
    string first;
    string last;

    int month;
    int day;
    int year;

    string street;
    string city;
    string state;
    string zip;

    string phone;
    string pStatus;

    extPersonType temp;

    cout << "Enter file name: ";
    cin >> filename;

    cout << endl;

    infile.open(filename);
    if (!infile)
    {
        cout << "Input file does not exists. "
             << "Program terminates!!!" << endl;
        return;
    }

    int i = 0;

    infile >> first >> last >> month >> day >> year;
    infile.ignore(100,'\n');
    getline(infile,street);
    getline(infile,city);
    getline(infile, state);
    infile >> zip >> phone >> pStatus;

    while (infile)
    {
        temp.setInfo(first,last,month,day,year,street,city,state,
                    zip,phone,pStatus);

        adBook.insertAt(i, temp);
        i++;

        infile >> first >> last >> month >> day >> year;    
        infile.ignore(100,'\n');
        getline(infile,street);
        getline(infile,city);
        getline(infile, state);
        infile >> zip >> phone >> pStatus;
    }
}

void saveData(addressBookType& adBook)
{
    ofstream outfile;

    char filename[50];

    cout << "Enter file name: ";
    cin >> filename;
    cout << endl;

    outfile.open(filename);
    if (!outfile)
    {
        cout << "Input file does not exists. "
             << "Program terminates!!!" << endl;
        return;
    }

    adBook.saveData(outfile);
}

void showMenu()
{
    cout << "Welcome to the address book program.";
    cout << "Choose among the following options:" << endl;
    cout << "1: To see if a person is in the address book" << endl;
    cout << "2: Print the information of a person" << endl;
    cout << "3: Print the names of person having birthday in a particular month" << endl;
    cout << "4: Print the names of persons between two last names" << endl;
    cout << "5: Print the names of persons having a particular status" << endl;
    cout << "6: Print the address book" << endl;
    cout << "7: Save data" << endl;
    cout << "9: Terminate the program" << endl;
}

Was This Post Helpful? 0
  • +
  • -

#3 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: c++ issues

Posted 29 September 2010 - 10:33 AM

Welcome to dream.in.code

Did you run this code ? If you ran it what errors did you receive ?
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: c++ issues

Posted 29 September 2010 - 10:39 AM

Did you add the arrayListType to be inherited?
Seems unlikely you would be asked to do it this way.

class addressBookType: public arrayListType<extPersonType>
{ ... 



Instead, I would suggest creating an object inside the addressBookType class :-

// List for 100 Addresses
arrayListType<extPersonType> addresses(100); 
...
...
if(addresses.isEmpty())
{ 
 ...



Was This Post Helpful? 0
  • +
  • -

#5 Black_list  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 10

Re: c++ issues

Posted 29 September 2010 - 11:09 AM

1>c:\users\atamask\documents\visual studio 2010\projects\dsassign4\dsassign4\addressbooktype.h(53): error C2664: 'arrayListType<elemType>::seqSearch' : cannot convert parameter 1 from 'std::string' to 'const extPersonType &'
1> with
1> [
1> elemType=extPersonType
1> ]
1> Reason: cannot convert from 'std::string' to 'const extPersonType'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.22
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

there was a post down the line by BlueFish, it died pretty hard but if its still there it has the rest of the program including the header this error comes from.
Was This Post Helpful? 0
  • +
  • -

#6 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: c++ issues

Posted 29 September 2010 - 11:21 AM

What don't you understand from that error message? I think it is clear enough.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,662
  • Joined: 23-August 08

Re: c++ issues

Posted 29 September 2010 - 11:25 AM

Merged duplicate topics. Please do NOT create a new topic when you already have an active one.
Was This Post Helpful? 0
  • +
  • -

#8 Black_list  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 10

Re: c++ issues

Posted 29 September 2010 - 11:37 AM

sorry, it didnt seem that active anymore.

anyway
yea...i have to have a class addressBookType that derives from arrayListType.... it seems so much better your way but that's kina why im here is the semantics.

and i get what the error is saying i just an kind of confused as how to go about making the array of objects needed as i cannot change the main.


Oh, and i dont get what the arrayListType<extPersonType> means either. what is the deal with the <>.

if someone could just tell me what

adBook.insertAt(i, temp);
i++;

does i think i could finish this god forsaken assignment.

This post has been edited by Black_list: 29 September 2010 - 11:35 AM

Was This Post Helpful? 0
  • +
  • -

#9 Black_list  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 10

Re: c++ issues

Posted 29 September 2010 - 12:09 PM

i also dont get why the function given in addressBookType for search sends a string when the search algorithm in arrayListType only accepts extPersonType Types.
Was This Post Helpful? 0
  • +
  • -

#10 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: c++ issues

Posted 29 September 2010 - 12:52 PM

View PostBlack_list, on 29 September 2010 - 07:37 PM, said:

yea...i have to have a class addressBookType that derives from arrayListType.... it seems so much better your way but that's kina why im here is the semantics.

Looking at it again, deriving from arrayListType, works well, if possibly slightly confusing to begin with.

Quote

i just an kind of confused as how to go about making the array of objects needed as i cannot change the main.

The class arrayListType is inherited, and so creates an array when addressBookType is constructed. Have a look at the arrayListType constructor.

Quote

Oh, and i dont get what the arrayListType<extPersonType> means either. what is the deal with the <>.

The brackets <> are used with templates, they bracket template parameters which can be used to pass types as arguments eg. arrayListType<int>.

Quote

if someone could just tell me what

adBook.insertAt(i, temp);
i++;

Notice, i is initialised to 0.
Objects of extPersonType are inserted into the arraylist. The location is incremented by 1 each time.
Was This Post Helpful? 0
  • +
  • -

#11 Black_list  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 10

Re: c++ issues

Posted 29 September 2010 - 01:42 PM

wow man thanks that fixed almost all of my problems. im sorry to keep bugging but the only error im getting now is from print in addressBookType and thats because i dont know what exactly to send to it.
i assume that i should use
seqSearch(); from arraylisttype but it requires a extPersonType type and the function i was given sends a string to that member.
Was This Post Helpful? 0
  • +
  • -

#12 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: c++ issues

Posted 29 September 2010 - 03:17 PM

View PostBlack_list, on 29 September 2010 - 08:09 PM, said:

i also dont get why the function given in addressBookType for search sends a string when the search algorithm in arrayListType only accepts extPersonType Types.


int addressBookType::search(string lName)
{
  arrayListType atemp;
  atemp.seqSearch(lName);
};



This looks like it could be a deliberate mistake. To test your understanding of what you are doing.

The class arrayListType uses a template, it can only handle the type/class that is passed as a unit. So name which is part of personType is unknown to arrayListType. Of course arrayListType could be changed to deal with personType specifically, but the whole idea of templating arrayListType is that it can be used more generally.

So which function can be changed?

Have a try at changing the function.

This post has been edited by #define: 29 September 2010 - 03:19 PM

Was This Post Helpful? 0
  • +
  • -

#13 Black_list  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 10

Re: c++ issues

Posted 29 September 2010 - 03:54 PM

well it sais to derive addressBookType in a way that would let it store objects of type extPersonType but what object would that be. how can i put in the constructed list if thats the one needed.
Was This Post Helpful? 0
  • +
  • -

#14 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: c++ issues

Posted 29 September 2010 - 05:27 PM

Quote

well it sais to derive addressBookType in a way that would let it store objects of type extPersonType

Yes, you have done that.

Quote

but what object would that be.



Quote

how can i put in the constructed list if thats the one needed.

The search item is not entered into the list, each item in the list is tested against the search item.
Was This Post Helpful? 0
  • +
  • -

#15 Black_list  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 10

Re: c++ issues

Posted 29 September 2010 - 07:00 PM

ah, so does that mean i have to find a way to store them in an extPersonType and check it.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2