Need help to create a main driver in c++

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2009
Posts: 3
Reputation: juniper2009 is an unknown quantity at this point 
Solved Threads: 0
juniper2009 juniper2009 is offline Offline
Newbie Poster

Need help to create a main driver in c++

 
0
  #1
24 Days Ago
Dear All
I would be very happy if you could help me!
I need to create a main() program which is be able to;

* reads in a list of words and their associated meanings from the
given test file(file.txt)(This file contains 10 lines)
* provide an interactive menu interface to find a ‘word’ and display
the meaning(s) of the searched ‘word’ if it exists. Make sure you
include all appropriate input data validation at the menu interface
and provide suitable messages for a successful or unsuccessful
search.

I need a scratch main program to get the idea of how to create a main driver function.
regards
Juniper
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,813
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
0
  #2
24 Days Ago
  1. // outline
  2.  
  3. // #include statements here
  4. // #define statements here
  5. // global variables here
  6. // function declarations here
  7.  
  8.  
  9. int main (int argc, char* argv[])
  10. {
  11. // variables local to main ()
  12. // more code
  13. return 0;
  14. }
  15.  
  16. // functions go here

This is a vague skeleton. You're going to have to show some effort or ask a more specific question for a more detailed answer.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: juniper2009 is an unknown quantity at this point 
Solved Threads: 0
juniper2009 juniper2009 is offline Offline
Newbie Poster
 
0
  #3
23 Days Ago
Thanks
But still I dont get that how to read the lines(string) from an external file " file.txt"
regards
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 52
Reputation: Skeen is an unknown quantity at this point 
Solved Threads: 1
Skeen's Avatar
Skeen Skeen is offline Offline
Junior Poster in Training
 
0
  #4
23 Days Ago
Originally Posted by juniper2009 View Post
Thanks
But still I dont get that how to read the lines(string) from an external file " file.txt"
regards
Here's a simple program on how to load the string into the program from a file;
  1. #include <fstream> // Header File for File Reading
  2. #include <iostream> // Header File for General I/O-put
  3. #include <string> // Header File for Strings
  4.  
  5. using namespace std; // Use namespacing
  6.  
  7. char String[1024]; // Create a string as a global var
  8.  
  9. bool LoadString() // Function for loading the string
  10. {
  11. ifstream in ("String.dat"); // Start Loading data from b.dat
  12. if (in.good()) // If the file is loadable (existing)
  13. {
  14. in >> String; // Load the string
  15. return true;
  16. }
  17. else // If the file is unloadable (nonexisting)
  18. {
  19. in.close(); // Stop Loading data form String.dat
  20. cout << "Could not load the file!" << endl; // Post error message
  21. system("PAUSE"); // Pause, to make the user able to read the error message
  22. return false; // Exit the program
  23. }
  24. in.close(); // Stop Loading data form String.dat
  25. }
  26.  
  27. int main()
  28. {
  29. if (!LoadString()){return 0;} // If the function returned
  30. cout << "The length of String is " << StringLength() << " characters.\n" << endl; // Post the length
  31. system("PAUSE"); // Pause, to make the user able to read the error message
  32. return 0; // Exit the program
  33. }
This code is loading the string, from the files dat, and returning the length of it, simply just use the string instead of returning the length.

And an example for two Strings, just made using copypaste:
  1. #include <fstream> // Header File for File Reading
  2. #include <iostream> // Header File for General I/O-put
  3. #include <string> // Header File for Strings
  4.  
  5. using namespace std; // Use namespacing
  6.  
  7. char String[1024]; // Create a string as a global var
  8.  
  9. bool LoadString() // Function for loading the string
  10. {
  11. ifstream in ("String.dat"); // Start Loading data from b.dat
  12. if (in.good()) // If the file is loadable (existing)
  13. {
  14. in >> String; // Load the string
  15. return true;
  16. }
  17. else // If the file is unloadable (nonexisting)
  18. {
  19. in.close(); // Stop Loading data form String.dat
  20. cout << "Could not load the file!" << endl; // Post error message
  21. system("PAUSE"); // Pause, to make the user able to read the error message
  22. return false; // Exit the program
  23. }
  24. in.close(); // Stop Loading data form String.dat
  25. }
  26.  
  27. bool LoadString2() // Function for loading the string
  28. {
  29. ifstream in ("String.dat"); // Start Loading data from b.dat
  30. if (in.good()) // If the file is loadable (existing)
  31. {
  32. char Line1[1024];
  33. in >> Line1 >> String; // Load the second string
  34. return true;
  35. }
  36. else // If the file is unloadable (nonexisting)
  37. {
  38. in.close(); // Stop Loading data form String.dat
  39. cout << "Could not load the file!" << endl; // Post error message
  40. system("PAUSE"); // Pause, to make the user able to read the error message
  41. return false; // Exit the program
  42. }
  43. in.close(); // Stop Loading data form String.dat
  44. }
  45.  
  46. int StringLength() // Function for finding the stirng length
  47. {
  48. string str (String); // set str
  49. return str.length(); // return the length of the string
  50. }
  51.  
  52. int main()
  53. {
  54. if (!LoadString()){return 0;} // If the function returned
  55. cout << "The length of String is " << StringLength() << " characters.\n" << endl; // Post the length
  56. if (!LoadString2()){return 0;} // If the function returned
  57. cout << "The length of String is " << StringLength() << " characters.\n" << endl; // Post the length
  58. system("PAUSE"); // Pause, to make the user able to read the error message
  59. return 0; // Exit the program
  60. }
Last edited by Skeen; 23 Days Ago at 5:38 pm.
// Skeen
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: juniper2009 is an unknown quantity at this point 
Solved Threads: 0
juniper2009 juniper2009 is offline Offline
Newbie Poster
 
0
  #5
19 Days Ago
Dear Skeen
It helped a lot
Thank you ver much indeed
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC