944,123 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1288
  • C++ RSS
Oct 21st, 2006
0

C++ Help....plez.

Expand Post »
Greetings C++ Lovers:

I'm a student very new to this C++. Yes I took Linux & UNIX. That was a year ago and I've never applied it to ANYTHING. If it's not too much trouble, I'm at a loss. A Big LOSS. You see, the reason I say this is bcuz. I took the initiative to go to my instructor to try to understand these C++ fundamentals.......and guess what.......It was still like reading this..."hjgddwufweuifdhweuf"! YEA!!! He tried breaking it down for me, now that I'm here (AT HOME) trying to figure this out I'm lost and DON'T KNOW WHAT I'm DOING :mad:

I've been given an assignment to write a program that asks the user to enter one of the following state abbreviations NC, SC, GA, FL, or AL. This program should display the name of the state that corresponds with the abbrev. Entered. Can you please help me? PLEASE? This IS frustrating. AM I to start out like this?....
char STATE[5];            /*   State abbreviation*/
{"North Carolina", "NC"},
{"South Carolina", "SC"}, 
{"Georgia", "GA"}, 
{"Florida", "Fl"},
{"Alabama", "Al"},
};
cout<<endl <<endl;
Please forgive for my ignorance to this course.

Your assistance means a whole lot!

Sincerely,

AnG’
Last edited by ~s.o.s~; Oct 21st, 2006 at 3:16 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AnG' is offline Offline
8 posts
since Oct 2006
Oct 21st, 2006
0

Re: C++ Help....plez.

Hmm maybe you need to look up on associative arrays HERE
But with your sparse knowledge of C++....
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Oct 21st, 2006
0

Re: C++ Help....plez.

Here is a starter. I would create a structure for the two strings, then array of that structure.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct states
  5. {
  6. char *stname;
  7. char *stabbr;
  8. };
  9.  
  10. states st[] = { /* State abbreviation*/
  11. "North Carolina", "NC",
  12. "South Carolina", "SC",
  13. "Georgia", "GA",
  14. "Florida", "Fl",
  15. "Alabama", "Al",
  16. };
  17.  
  18.  
  19. int main(int argc, char* argv[])
  20. {
  21. int array_size = sizeof(st) / sizeof(st[0]);
  22. for(int i = 0; i < array_size; ++i)
  23. {
  24. cout << st[i].stname << "\t" << st[i].stabbr << endl;
  25. }
  26. return 0;
  27. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Oct 21st, 2006
0

Re: C++ Help....plez.

And along with the above code provided by Mr. Dragon, you might want to use fgets( char* my_array, SIZEOFARRAY, stdin ) to accept input from the user and a function which searches the entire structure array for the given string and then returns its state equivalent.

But personally i would advice you to go with the associative array or the STL map construct, unless you have been instructed not to do so, since it makes the code less cluttered, more logical and extensible. One thing you would never want to do in programming is to reinvent the wheel.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Oct 21st, 2006
0

Re: C++ Help....plez.

I will try that. Thank you so much. And you are correct. When it comes to C++, I am "dense" in this region. I truely thank you for your time though. I was sincerely considering withdrawing from this class, but due to some compassionate collaborators, I'm liberated!


Yours Truely,

AnG'
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AnG' is offline Offline
8 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: What is the Command-Line Argument for???
Next Thread in C++ Forum Timeline: Need help with some syntax errors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC