needed big time hw due and late

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 3
Reputation: damionspencer is an unknown quantity at this point 
Solved Threads: 0
damionspencer damionspencer is offline Offline
Newbie Poster

needed big time hw due and late

 
2
  #1
Sep 7th, 2004
:mad: :mad: I've been trying to write this program that is suppose to read in a text file manipulate in and give the following out put infact here is the question

Implement a program that uses a form-letter template to generate form letters. Your program should read in a form-letter template from a file. The form-letter template has "holes" in it that are to be filled in with user-entered values. The holes are represented by a pair of @ signs. For example, suppose this is read in from a form-letter template file:

Congratulations, @@! You've just won @@!
To collect, please send $100 to

And suppose the user enters these two values for the two @@ holes:

Raheel Azhar
a new house

Your program should then print this form letter:

Congratulations, Raheel Azhar! You've just won a new house!
To collect, please send $100 to
:mad:

this is what i have so far but all i get is compilation errors

#include <iostream>
#include <string>

using std::cout;
using std::cin;

class FormLetter
{
public:
string letterTemplate;

//private:
void generateLetter();
};

FormLetter::FormLetter(string fname)
{

letterTemplate = fname;

f.open("letterTemplate", ios::in);
f.close();

}

void generateLetter()
{
string input;
int count = 0;
++count;
while(count <4)
{
getline(letterTemplate,'@');
cout << "Enter insertion text: " << endl;
cin >> input << endl;
letterTemplate.insert(find_first_of '@', input);
generateLetter();
cout << letterTemplate << endl;

}
}

int main()
{
FormLetter formLetter1("letterTemplate.txt");
formLetter1.generateLetter();
return 0;
}


please help
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: needed big time hw due and late

 
0
  #2
Sep 8th, 2004
What kinds of compile errors?

I imagine it complains about these lines:

using std::cout;
using std::cin;

try just "using std;" instead.

and you make a constructor like this:

FormLetter::FormLetter(string fname)

but it isn't in the class definition; try adding "FormLetter(string fname);" after "public:" in the FormLetter class.

void generateLetter()

needs to be like this:

void FormLetter::generateLetter()

and so on; the compiler should be pointing out the line number that has a problem and a general idea of what the problem is....
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: needed big time hw due and late

 
2
  #3
Sep 8th, 2004
I think your question is about c++ ... so it should be posted in c++ forum ... you'll get replies there.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,443
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: needed big time hw due and late

 
0
  #4
Sep 8th, 2004
Originally Posted by Chainsaw
I imagine it complains about these lines:

using std::cout;
using std::cin;
Why?

Originally Posted by Chainsaw
try just "using std;" instead.
ITYM
  1. using namespace std;
Except in 'toy' programs, you really don't want to grab the whole namespace -- doesn't that kind of defeat the purpose of the namespace?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 3
Reputation: damionspencer is an unknown quantity at this point 
Solved Threads: 0
damionspencer damionspencer is offline Offline
Newbie Poster

Re: needed big time hw due and late

 
0
  #5
Sep 8th, 2004
Originally Posted by Chainsaw
What kinds of compile errors?

I imagine it complains about these lines:

using std::cout;
using std::cin;

try just "using std;" instead.

and you make a constructor like this:

FormLetter::FormLetter(string fname)

but it isn't in the class definition; try adding "FormLetter(string fname);" after "public:" in the FormLetter class.

void generateLetter()

needs to be like this:

void FormLetter::generateLetter()

and so on; the compiler should be pointing out the line number that has a problem and a general idea of what the problem is....
thanks for the reply I will try this I am more familiar with java
so thats why I am having a few headaches

i am also a new member to this site
so I appreciate any help i can get
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 48
Reputation: mister-fett is an unknown quantity at this point 
Solved Threads: 0
mister-fett's Avatar
mister-fett mister-fett is offline Offline
Light Poster

Re: needed big time hw due and late

 
2
  #6
Sep 11th, 2004
Unless you HAVE TO use specific code, this works GR8!
(Sorry if its a little to late!)
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5. char name[50];
  6. char item[50];
  7. char exit[10];
  8. printf("What is your name?\n\a");
  9. gets(name);
  10. printf("What is one thing you REALLY want?\n\a");
  11. gets(item);
  12. printf("Congratulations, %s! You just won %s!\nTo collect, please send 100$ to California.\n(Press enter to exit)",name,item);
  13. gets(exit);
  14. return 0;
  15. }

Attached is the compiled exe in a zip file.
Attached Files
File Type: zip hw.zip (27.4 KB, 1 views)
Cheese. In fact, I rather dislike cheese.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,443
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: needed big time hw due and late

 
0
  #7
Sep 11th, 2004
Originally Posted by mister-fett
Unless you HAVE TO use specific code, this works GR8!
:rolleyesrogram for more than a couple days before you start teaching.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: needed big time hw due and late

 
1
  #8
Sep 12th, 2004
Originally Posted by Dave Sinkula
:rolleyesrogram for more than a couple days before you start teaching.
Hey now. Be nice.

If there's something wrong with what he's posted, wouldn't it be more helpful to point out what's the problem/.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 48
Reputation: mister-fett is an unknown quantity at this point 
Solved Threads: 0
mister-fett's Avatar
mister-fett mister-fett is offline Offline
Light Poster

Re: needed big time hw due and late

 
0
  #9
Sep 12th, 2004
Come on, I was just trying to help. I have been programming in various languages for about three years, I am just new to C (I have been learning it for a month, but I got the compiler a week ago. I have known Dr Scheme for about nine months, PBasic for three years, and have used National Instruments Labview for two years.)
Besides, it works, doesn't it?
I know there is a better way to do it, but the way I described and compiled works.

I do understand, though, that my way does not fit the parameters set by the assignment. I will read more carefully next time. Although it completes the task, my program does not use files or forms. Sorry!

Program for more than a couple days before you start teaching.
Cheese. In fact, I rather dislike cheese.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,443
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: needed big time hw due and late

 
0
  #10
Sep 12th, 2004
Originally Posted by alc6379
Hey now. Be nice.

If there's something wrong with what he's posted, wouldn't it be more helpful to point out what's the problem/.
There is one function that should be avoided at all costs -- gets. Millions of Google hits can tell you why. But I can provide links if you'd like. Any program that contains one of these constructs stinks of a C newbie:


  • void main()
  • gets(string);
  • fflush(stdin);
Originally Posted by mister-fett
Unless you HAVE TO use specific code, this works GR8!
(Sorry if its a little to late!)
     #include <stdio.h>
     #include <string.h>
     int main()
     {
     	char name[50];
     	char item[50];
     	char exit[10];
     	printf("What is your name?\n\a");
     	gets(name);
     	printf("What is one thing you REALLY want?\n\a");
     	gets(item);
 	printf("Congratulations, %s! You just won %s!\nTo collect, please send 100$ to California.\n(Press enter to exit)",name,item);
     	gets(exit);
     	return 0;
 }
The original code was C++, for which different methods are used for input and output. And this code uses the most dangerous function in the C standard library as an "improvement". And the last one also uses a reserved identifier -- the name of a standard library function.

Originally Posted by mister-fett
Besides, it works, doesn't it?
I know there is a better way to do it, but the way I described and compiled works.
That is the most dangerous way to code: it "works". (By accident, not by design.)

It is never safe, but it "works".

Sometimes the only way to capture someone's attention is to be a little bit of an ass. Try not to take it personally. Try to take it as constructive criticism without wiggle room.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC