| | |
needed big time hw due and late
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2004
Posts: 3
Reputation:
Solved Threads: 0
: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
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 questionImplement 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
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....
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....
I think your question is about c++ ... so it should be posted in c++ forum ... you'll get replies there.
•
•
•
•
Originally Posted by Chainsaw
I imagine it complains about these lines:
using std::cout;
using std::cin;
•
•
•
•
Originally Posted by Chainsaw
try just "using std;" instead.
C Syntax (Toggle Plain Text)
using namespace std;
"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
•
•
Join Date: Sep 2004
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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....
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
Unless you HAVE TO use specific code, this works GR8!
(Sorry if its a little to late!)
Attached is the compiled exe in a zip file.
(Sorry if its a little to late!)
C Syntax (Toggle Plain Text)
#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; }
Attached is the compiled exe in a zip file.
Cheese. In fact, I rather dislike cheese.
•
•
•
•
Originally Posted by mister-fett
Unless you HAVE TO use specific code, this works GR8!
rogram 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
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!
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.
•
•
•
•
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/.
- 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; }
•
•
•
•
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.
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
![]() |
Other Threads in the C Forum
- Previous Thread: string size problem
- Next Thread: A Little Advice Please!
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop interest kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






