Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

I need help with a C++ mail sorting application

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a beginner and I was only able to do the first part of this program. I want to write a program that sorts mail received in a post office and develop this program using the OOP style with C++ language.

i. The user counts the number of letters to be processed and inputs the value into the application
ii. The application creates the exact number of entries according the number of letters already counted.
iii. The user then picks a letter and inputs three (3) details on the letter: Name of recipient, address of recipient and zip/post code (zip code is a 4 digit number). iv. The application must be able to store all the entered details in the memory v. The application must be able to present any or all of these details through MS-DOS output according to the search command definitions below:
1)Search recipient: Enables the user to query a recipient’s details by entering the name.
2)Search records: Enables the user to query the entire record entries as a table.
3)earch postcode entries: Enables the user to query records which are sorted based on postcode and the number of mails for each postcode.
4)Search entry number: Enables the user to search for any letter using the entry number

This is what I've done so far And I don't know how to do the command definitions.
#include<iostream>
#include<string>>

using namespace std;
Class Postport
{
private:
int letters;
int Zipcode[1000];
string name[1000], address[1000];

public:
void input();
void output();
};

void Postport::input()
{
cout<<"enter number of letters: ";
cin>>letters;
for(int i=0;i<letters;i++)
{
cout<<"enter details of person: "<<i+1"-> \n"
cout<<"name: ";
cin>>name[i];
cout<<"address: ";
cin>>address[i];
cout<<"zip code: ";
cin>>Zipcode[i];
}
}

void Postport::output()
{
cout<<"\n\nentry\tname\taddress\tZipcode\n";
for(int i=0;i<letters;i++)
{
cout<<i+1<<"\t"<<name[i]<<"\t"<<address[i]<<"\t"<<Zipcode[i]<<"\n";
}
}

int main()
{
class Postport may;
may.input();
may.output();
return 0;
}

 
Rancher
Posts: 344
11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tido - first thing people need to help them help you is some nicely formatted code. Select what you to format, then press the 'Code' button. I've had to add the indentation that was lost when your code got posted as text so apologies if not as you intended. I've also corrected a couple of typos - presumably you haven't tried compiling this?

Cheers
John
 
Tido Gumede
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John thank you so much. I fixed the errors in my code and it worked. The only problem I'm having now is writing the search command definitions.  I don't even know where to start
 
John Matthews
Rancher
Posts: 344
11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest a modification in the way you store the entries. At the moment you have 3 x 1000 size arrays. I think that should be a single array of 1000 structures, with the structure consisting of zipcode, name and address fields. That structure is then your letter(?) 'object'.

To search for a recipient, you would then go through the array of letters looking for an entry whose name field matched the entered name. Does that help?

By the way, logically your array and letters value is a list, and C++ provides suitable classes/templates with methods that make writing code such as this a lot easier. Have you been told not to use them, or is that an option? Actually the best bet would probably be the simpler vector template eg.

http://www.cplusplus.com/reference/vector/vector/
https://thispointer.com/c-how-to-find-an-element-in-vector-and-get-its-index/

(These were just top results from google searches, might not be the best.)
 
John Matthews
Rancher
Posts: 344
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and your letter 'structure' would probably be a class.
 
Tido Gumede
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much!!! I will try this
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic