complicated alot... HEEEEELP!!!! X(

Part I
Create a text file named FF.txt that stores the information about your friends and family in the following order: first name, last name, gender, relation (eg, friend, aunt, brother, cousin etc), for at least 20 people. For example, your text file may contain entries as follows:
Sadia Jameel F friend
Omar Al-Kubaisi M uncle
Noora Al-Mannai F cousin
……..
and so on.
Part II
Write a C++ program containing one or more loops that will use the file you created above in Part I in the following manner:
a. Display the names of all your friends in the first list, the user is asked to press Enter after which the program displays the names of all your relatives in the second list.
b. For each entry in the file, the program creates another file named firstname_lastname.txt which contains the text of your invitation card as follows:
To Mr Omar Al-Kubaisi
Dear uncle Omar,
I would like to invite you to my birthday party at 7pm on __________ at ___________. I hope you can come.
I will be really excited to see you in my party.
Sincerely yours,
Your name
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main ()
{
char FirstName ,LastName,Gender,Relation,enter;
ifstream inputfile;
inputfile.open("FF.txt");
if (!inputfile)
cout<< "Error opening file.\n";
else

inputfile>>FirstName>>LastName>>Gender>>Relation;
while (!inputfile.eof())
{
if (Relation =='f','r','i','e','n','d')
cout<<FirstName ,LastName;
}
cout<<"press enter\n";
cin>>enter;
inputfile.close();
ifstream inputfile;
inputfile.open("FF.txt");
if (!inputfile)
cout<< "Error opening file.\n";
else

inputfile>>FirstName>>LastName>>Gender>>Relation;
while (!inputfile.eof())
{
if (Relation=='r','e','l','a','t','i','v','e')

{
cout<<FirstName ,LastName;

} 


cout<<"press enter\n";
cin>>enter;
inputfile.close();
}
inputfile>>FirstName>>LastName>>Gender>>Relation;
while (!inputfile.eof())
{
ofstream outfile;
outfile.open(FirstName+" "+LastName);
outfile << endl << "To"<<FirstName<<" "<<LastName<<endl<<"would like to invite you to my birthday party at 7pm on __________ at ___________.I hope you can come."<<endl<<"I will be really excited to see you in my party."<<endl<<"Sincerely yours,"<<endl<<"Your name";
outfile.close();
}
}

and one thing.. can u please dont use array... thank u
Last edited on
It's now complicated because you've coded yourself into corner; everything is in MAIN().

This would be best written in COBOL.

I suggest you return you your original design and regroup your functions into logical steps.

Then you can focus your attention on each step separately.

Variables FirstName and so on are defined as type char. That can hold only a single letter. You need to use either type std::string or a c-string (which is an array of characters).

Quote: "please dont use array".
Is that a personal preference or a restriction imposed by whoever set the question?

Bear in mind that a string such as "would like to invite you..." is in fact an array of characters, so if you impose that restriction too pedantically, this project may be impossible. :)



Last edited on
I am having trouble reading your code because it's so poorly formatted.
We are here to help you, if your going to make it harder on us than necessary, how would you feel?

First, your program doesn't even compile.
Fix that first.
Remove any statements that don't work.
change void main () to int main ()

You have ifstream inputfile; on line 8 and 23 remove one.

Put {} around your if/else statements so we know where you intend for them to begin and end. If you do not have {} it will only process the 1st line after the if. I think you have some of yours missing.

I would guess the logic isn't going to work the way it is.

Looks like this is the code for part 2, does your code for part 1 work ok ?

put return 0;
at the end of main.
Here is a piece to get you started

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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main ()
{
    string FirstName ,LastName,Gender,Relation,enter;
    ifstream inputfile;
    inputfile.open("FF.txt");
    if (!inputfile)
    {
    cout<< "Error opening file.\n";
    }  // End if
    else
    {
    while (!inputfile.eof())
    {
    inputfile>>FirstName>>LastName>>Gender>>Relation;
    if (Relation =="friend")
    {
    cout << "F " <<FirstName << " L " << LastName << " G " << Gender << " R " << Relation << endl;
    }
    }// End While
    } // End Else

    inputfile.close();
    return 0;
}
Topic archived. No new replies allowed.