Can someone help me make sense of this program?

NO I do not want you to do my homework for me. Just thought I would say that first thing.

The issue is I always have problems understanding the assignments my programming professor gives to me. Its too technical and lengthy for me and I need someone to put it into PLAIN ENGLISH for me and tell me step by step what I am supposed to do...
I can't write a program if I don't understand the steps I need to take and in what order and what I am trying to accomplish.

Someone please help me make sense of the instructions for this program.

It would be GREATLY appreciated.


P.s. The instruction sheet is very very long.


You will be creating a christmas card address file. To create this file, you will work with a named input file, an output file that is opened in both out and app modes, a few ctype functions, and the string class.

The program should be written so that the main function does little else but call other functions such as:
PrintGreetingScreen - print a greeting on screen that explains purpose of the program. Let the user press enter key to continue.
OpenInputFile
OpenOutputFile
ReadInRecords
DisplayRecordsOnScreen
WriteToOutputFile
OpenOutputFileInAppend
AddNewRecords
PrintCosingScreen - print closing message on screen and let user press enter to exit the program


Other requirements for the program are:
1. The input file for this lab is addressList.txt. Get a copy from my website.
2. The addressList.txt input file has been written using a dollar sign($) as a field delimiter. Each line of data in the file contains information for one record (last name, first name, street address, city, state, zip code). All fields except for the state and zip code may contain spaces. The state fiels will contain only the two letter state abbreviation. The zip code will be a 5 digit number. The field sizes for the first 4 fields needs to be resized so that each fiels is the size listed as follows:
Last name - new field size 20
First name - new field size 20
Street address - new field size 25
City - new field size 20

3. Using the addressList.txt input file, write a program that will perform the following tasks:
a. read the data one field at a time from addresslist.txt input file using string class data type. the input file stream should be declared as ifstream. print copies of the incoming records on the screen in format of your choice as you process them.
b. resize each field to its appropriate size as show above. if field is less than required size pad the end of the field with spaces.
c. combine all fields from one record into a single string in this order: last name, first name, street address, city, state, zip code. do not put $ back into the record. Store all the new records into another string array called newStrings. Each element in this array will be 92 bytes long. this is the array you will pass in the main function to WriteToOutputFile.
d. Write the newly combined string records to an output file called lab3output.txt. this file should be declared as an ofstream type and opened initally with a file access flag ios::out. WriteToOutputFile is a function that should be called to the main function.

4. After you have converted all the records from the input file and written them to the output file, close the output file.

5. Reopen the output file using a file access flag ios::app

6. Allow the user to enter information to add to the christmas card list using the following data validation:

a. the last name, first name, and city fields must contain no less than 1 and no more than 20 characters. if this condition is not met, ask the user to reenter the data.

b. the street address field must contain no less than 1 and no more than 25 characters. if condition is not met, ask user to reenter data.

c. the state abbreviation field must contain exactly 2 characters and must be one of the 50 correct state abbreviations. if condition is not met, reenter.

d. the zip code field must contain exactly 5 characters and they must be digits. if condition is not met, reenter.

7. After the user has enter all the data for one record, perform the following tasks:

a. resize the last name, first name, street address, and city fields so they match the values given in the table above. if the field is less than required size pas end of field with spaces.

b. combine all fields of one record into a single string as in step 3c above

c. write the new record to the output file so that it is appended to the end of the file

d. the program should allow the user to enter the data for new records until the user wishes to terminate the process.

8. Allow a maximum of 50 records in the final file. That is, after reading in all current records and then allowing user to add additional records, you will not allow more than 50 records total in the final file. this when you declare the array, you may use a MAX-SIZE of 50.



This is the code I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*Program to create a Christmas card address file*/

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <string>
#include <stdlib.h>
std::ifstream infile("addressList.txt");

using namespace std;

void PrintGreetingScreen()
{
    cout << "\n\t\tWelcome!\n\n";
    cout << "The purpose of this program is to create a Christmas card ";
    cout << "address file.\n\n";
    cout << "Press enter to continue..." << endl;

    cin.ignore();
}

void OpenInputFile()
{
ifstream inputFile;
string filename;

    cout << "What file would you like to open?\n";
    cin  >> filename;

    if (filename == "addressList")
    {
        cout << "Opening the file...\n\n";
        //Opens the file
        inputFile.open("addressList.txt");
        cout << "Input file opened successfully.\n";
    }
    else
    {
        cout << "Error. Please try again.\n";
        //Terminate program
        exit (EXIT_FAILURE);

    }
}

void OpenOutputFile()
{
    //Needs to be created first?
}

void ReadInRecords()
{
string line;
ifstream myfile ("addressList.txt");

 if (myfile.is_open())
 {
    while ( myfile.good() )
    {
    getline(myfile, line, '$');
      cout << line << endl;

    }
    myfile.close();
 }

else
{
    cout << "Unable to open file";
}
}

void DisplayRecordsOnScreen()
{

}

void WriteToOutputFile()
{

}

void OpenOutputFileInAppend()
{

}

void AddNewRecords()
{

}

void PrintClosingScreen()
{

cin.get(); //Ends after user hits enter
cout << "\nPress enter to exit the program.\n";


}

int main()
{
   PrintGreetingScreen();
   OpenInputFile();
   ReadInRecords();
   PrintClosingScreen();
    return 0;
}


Please help! Thank you in advance.
Last edited on
Now that's really long for a question.

It would be helpful if you specify what words/sentences/paragraphs you can not understand.
Santa's Little Helper

The business is going bad this year for Santa. So he decided to sell his famous list to the International Committee of Publicity and Commerce (ICPC), that will use it to improve the quality of life of the people.

The ICPC requires an special format for these important documents, so Santa has contracted you to make a program that would fix all his registers

Input
The input contains a lot of registers. Each register has the fields: last name, first name, street address, city, state and zip code, delimited by a dollar sign('$')

Output
Output all the registers using a fixed field width (filled with spaces ' ') and without delimiter
The fields widths are
Last name 20
First name 20
Street address 25
City 20
State 2
Zip code 5


Example input
Foo$Bar$123 Fake Street$Island of Atlas$XX$42013

Example output
Foo                 Bar                 123 Fake Street          Islan of Atlas      XX42013
That's basically what you need to do. How to do it (and other details), is explained in detail in each step


> void OpenOutputFile()
> Needs to be created first?
Opening a file in output mode would attempt to create it
Do I read in the data into an array or a string?...
I don't understand what is the next step.... I am still stuck at trying to read in the records. I open the file and then I read in the records using an array? a string?
Last edited on
Read it into a string. From there tokenize it with a delimiter of $ sign.

http://www.cplusplus.com/reference/cstring/strtok/
> Do I read in the data into an array or a string?...
Do what you want ‘cause a pirate is free

You really shouldn't ask that kind of thing, if you know how to read in a string, go ahead an do it
I would prefer to read a record in a record
1
2
3
4
5
6
struct record{
   std::string
      last_name,
      first_name,
      //...
};
reading each field with http://www.cplusplus.com/reference/string/string/getline/ to stop at the delimiter
Topic archived. No new replies allowed.