| | |
I need help with this particular c++ problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Write a program which reads a text from a file declared by the user.
If the file does not exist a message should state this and the program
should be terminated.
If the file opens with success the program should read the text and then output the uppercase letters A-Z and each of their counts and same of the lowercase letters a-z.
The program will then print the percentages of capital letters for every letter A-Z and small letters for every letter a-z to the output file also declared the user.
This program's main function should be a bunch of function calls and declarations. and the information for the count function should be put into an array of structures, and the information should be passed as reference also the input and output files should be passed as reference.
Also there are to be no global variables.Please help me someone. thanks in advance.
Below is what I have done so far:
If the file does not exist a message should state this and the program
should be terminated.
If the file opens with success the program should read the text and then output the uppercase letters A-Z and each of their counts and same of the lowercase letters a-z.
The program will then print the percentages of capital letters for every letter A-Z and small letters for every letter a-z to the output file also declared the user.
This program's main function should be a bunch of function calls and declarations. and the information for the count function should be put into an array of structures, and the information should be passed as reference also the input and output files should be passed as reference.
Also there are to be no global variables.Please help me someone. thanks in advance.
Below is what I have done so far:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> using namespace std; struct letters { char ch; int lcount; }; void main() { void Explanation(); int OpenFile(ifstream&, ofstream&); int Count(ifstream&, letters[], int); void PrintResult(letters[], int); const int Size = 52; letters List; ifstream infile; ofstream outfile; Explanation(); OpenFile(infile, outfile); Initialize(List, Size); Count(infile, List, Size); PrintResult(List, Size); } void Explanation() { cout << "This program reads a text from a file declared by you the user." << endl; cout << "If the file does not exist a message will state this and the program\n" << "will be terminated." << endl << endl; cout << "If the file opens with success the program will read the text and then\n" << "output the letters in that file, both upper and lower case and the count\n" << "of each letters appearance in the file." << endl << endl; cout << "The program will then print the total number as well as the percentages of\n" << "capital letters for every letter A-Z and small letters for every letter a-z\n" << "to the output file also declared by you the user." << endl << endl << endl; } int OpenFile(ifstream& infile, ofstream& outfile) { string inputfile; string outputfile; cout << "Please enter the name for the input file: "; cin >> inputfile; cout << endl; infile.open(inputfile.c_str()); if (!infile) { cout << "Cannot open the input file!" << endl; return 1; } cout << "Now enter the name for the output file: "; cin >> outputfile; cout << endl; outfile.open(outputfile.c_str()); }
Last edited by alc6379; Feb 28th, 2005 at 5:55 pm.
•
•
•
•
Originally Posted by Acidburn
ok had a chance to skim.... but void main?? main always returns a value...
int main(void)
or
int main()
not sure what the problems are could you state them? and please use code tags
also why are you declaring the file streams in main? You should jsut point the open file function the the file name where it declares and instanciates the file streams. If you need to count lines, do it in the Open function and return that value, then use that returned value in main.
anyways, just skimming through it.
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
>void main is acceptable
The language standard explicitly states that main must return an int. This has always been the case, except in the past the language has been imprecise enough for some to misinterpret it. Some compilers support void main, but only to cater to stupid people who don't know what language they're using.
The language standard explicitly states that main must return an int. This has always been the case, except in the past the language has been imprecise enough for some to misinterpret it. Some compilers support void main, but only to cater to stupid people who don't know what language they're using.
New members chased away this month: 4
read
http://homepages.tesco.net/~J.deBoyn...void-main.html
Unfortunetly there is a valid claim to using void main(). It's bad practice, but does; technically, follow the standard (the specific standard mentioned in that article).
http://homepages.tesco.net/~J.deBoyn...void-main.html
Unfortunetly there is a valid claim to using void main(). It's bad practice, but does; technically, follow the standard (the specific standard mentioned in that article).
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
•
•
•
•
Originally Posted by BountyX
read
http://homepages.tesco.net/~J.deBoyn...void-main.html
Unfortunetly there is a valid claim to using void main(). It's bad practice, but does; technically, follow the standard (the specific standard mentioned in that article).
•
•
•
•
Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.
*behavior where two or more possibilities exist and no further requirements on which is chosen in any instance
[edit]Follow some of the links and find that corrections have been made. Or that fun restrictions apply:
•
•
•
•
If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain are declared as void, you must use the exit function.
"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
•
•
•
•
Originally Posted by bill13
i need your help.is it possible to give a solution to the following problem.
Store random numbers into two-dimensional array of 6 * 6 and interchange first 3 rows with last three rows.
i would be grateful to hear from you soon.
thank you in advance.
"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
>does; technically, follow the standard
Technically, no. Technically, the standard allows for non-portable extensions, but doesn't specify those extensions in any way. Therefore, void main does not follow the standard. It only has the potential for implementation-defined behavior rather than undefined behavior if the implementation documents it.
Your argument could be applied to any language or library extension.
Technically, no. Technically, the standard allows for non-portable extensions, but doesn't specify those extensions in any way. Therefore, void main does not follow the standard. It only has the potential for implementation-defined behavior rather than undefined behavior if the implementation documents it.
Your argument could be applied to any language or library extension.
New members chased away this month: 4
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Cellphones, PDAs and Handheld Devices)
- Connection Problems (Networking Hardware Configuration)
- Encoding (Unicode) problem in IE 6.0 (Web Browsers)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
Other Threads in the C++ Forum
- Previous Thread: dynamic array of structures problem
- Next Thread: Building a database application
Views: 2072 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






