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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:13:14+00:00 2026-05-30T08:13:14+00:00

So for Homework I have to create this program that reads from a text

  • 0

So for Homework I have to create this program that reads from a text file, puts into an object array, sorts the array using a bubble sort. The bubble sort has to use the alphaGreat() function in PhoneEntry. I have that done fine. The problem comes in my alphaGreat function when I need to compare the lastName to the passed objects last name. How do I go about doing this? This has been a hard program for me so far…

Driver

#include <iostream>
#include <fstream>
#include <string>
#include "phoneEntry.h"
using namespace std;

void mySort(double array[], int size)
{
    double temp;
    bool inOrder = false;
    for (int i = size - 1; i > 0 && !inOrder; i--)
    {
        inOrder = true;
        for (int j = 0; j < i; j++)
        {
            if (array[j] > array[j + 1])
            {
                inOrder = false;
                temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }
        }
    }
};

int main()
{   
    const int MAXNUM = 500;
    PhoneEntry entry[MAXNUM];
    ifstream filezilla;
    filezilla.open("phone.txt");
    int count = 0;

    if(filezilla)
    {
        while(count < MAXNUM && entry[count].readEntry(filezilla))
        {
            count++;
        }
        mySort(entry, count);
        for(int i = 0; i < count; i++)
        {
            entry[i].writeEntry(cout) << endl;
        }
    }
    else
    {
        cout << "Four Oh Four - File Not Found" << endl;
    }

    return 0;
}

Phone Entry

#include <iostream>
#include <fstream>
#include <string>
#include "phoneNumber.h"
using namespace std;

class PhoneEntry
{
    private: 
        PhoneNumber phone;
        string firstName,
               lastName;
        void _writeDots(ostream& fout, int n) const;
        bool alphaGreater(const PhoneEntry&) const;
    public:
        istream& readEntry(istream&);
        ostream& writeEntry(ostream&) const;

};

istream& PhoneEntry::readEntry(istream& Sin)                    
{
    Sin >> firstName >> lastName;
    phone.readNumber(Sin);

    return Sin;
};
///////////////////////////////////////////
ostream& PhoneEntry::writeEntry(ostream& Sout) const            
{   
    const int num = 28;

    Sout << firstName << ", " << lastName;
    int fill = num - (firstName.length() + lastName.length());
    _writeDots(Sout, fill);

    phone.writeNumber(Sout);

    return Sout;
};
///////////////////////////////////////////
void PhoneEntry::_writeDots(ostream& fout, int n) const
{
    if(n % 2)
        fout << " .";
    else
        fout << ".";


    for(int i = 0; i < n/2; i++)
    {
        fout << " .";
    }
};

bool PhoneEntry::alphaGreater(const PhoneEntry& item) const
{
    bool alpha = false;
    // I have first and last names reversed in my entire program
    if(item.compare(firstName) == 0)
    {
        if(item < lastName)
        {
            alpha = true;
        }
        else 
        {
            alpha = false;
        }
    }
    else if(item < firstName)
    {
        alpha = true;
    }
    else
    {
        alpha = false;
    }

    return alpha;
}

Phone Number

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class PhoneNumber
{
    private: 
        int areaCode, 
            prefix, 
            suffix;
    public: 
        istream& readNumber(istream&);
        ostream& writeNumber(ostream&) const;
};

istream& PhoneNumber::readNumber(istream& Sin)                  
{
    Sin >> areaCode >> prefix >> suffix;
    return Sin;
};
///////////////////////////////////////////
ostream& PhoneNumber::writeNumber(ostream& Sout) const          
{
    Sout << areaCode << "-" << prefix << "-" << suffix;
    return Sout;
};

Text File

Fleischman Robert 336 746 5525
Rorie Tim 336 746 6915
Johnson Gary 336 746 6985
Hoyt James 336 781 2668
Krass Mike 606 393 5355
Rust James 606 393 5525
Sekutera Norman 606 746 3635
Kennedy Amy 606 746 3985
Behrends Leonard 606 746 4235
Rueter Clarence 606 746 4395
Rorie Lonnie 606 746 4525
Beck Keith 606 746 4655
Bornemeier Eugenia 606 746 4775
Fleischman Arlo 606 746 4915
Rorie Scott 606 746 4985
Elliott Alice 712 746 2166
Keller Thomas 712 746 2196
Halvorsen Lorenz 712 746 2211
Slominski Greg 712 872 2006
Blunt Ed 712 872 2041
Bailei David 712 872 2051
Krouse John 712 872 2063
Furgerson Glen 712 872 2064
Behii Michelle 712 872 2123
Harris Mark 712 872 2124
Ropers Lorens 712 872 2164
Krejdl Wayne 804 274 2695
Kitchen Pat 804 274 2805
Jones Terry 804 274 2865
Schulz Harvey 804 274 3145
Griffith Joe 804 274 3165
Sailors Loretta 804 274 3225
Johnston Jeffrey 804 274 3285
Jicha James 804 274 3485
Sailors Eugene 804 393 5525
Hanshaw Harold 804 393 5565
Fischer Francis 804 393 6065
Bogenreit Charles 804 393 6155
John Ted 804 393 6175
Fischer William 804 393 6225
Schweitzer Fred 804 746 2285
Clements Richard 804 746 2340
Kuehn Oral 804 746 2635
Huxbold Kevin 804 746 2665
Bornemeier Dan 804 746 2685
Root Howard 804 746 3535
Hanshaw Gary 804 746 5525
Sheard Donald 804 746 6355
Smith Brett 804 746 6595
Schreiner James 804 746 6645

Right, there’s a lot going on. The main thing is that I need to know how to access the object variable firstName that was passed into alphaGreater is the main thing. Thanks in advance!

  • 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-30T08:13:15+00:00Added an answer on May 30, 2026 at 8:13 am

    Code like this:

        if(item < lastName)
    

    Should be like this:

        if(item.lastName < lastName)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a homework assignment where I need to take input from a file
I have an assignment that I have to create a randomly sized 3D array,
I have this homework that I gotta finish, but then something about it is
This is homework, just so that's mentioned. I have project called AdventCalendar, which is
I have this insane homework where I have to create an expression to validate
I have a homework assignment that asks to create an order form. The order
I'm trying to create this webpage for homework where I have to state which
(this is indirectly a part of a much larger homework assignment) I have something
This is currently a homework project that me and my teammate are stuck on.
For homework, I'm trying to create a CustomButton that has a frame and in

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.