C++ Help....plez.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 8
Reputation: AnG' is an unknown quantity at this point 
Solved Threads: 0
AnG' AnG' is offline Offline
Newbie Poster

C++ Help....plez.

 
0
  #1
Oct 21st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #2
Oct 21st, 2006
Hmm maybe you need to look up on associative arrays HERE
But with your sparse knowledge of C++....
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

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

 
0
  #3
Oct 21st, 2006
Here is a starter. I would create a structure for the two strings, then array of that structure.
  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #4
Oct 21st, 2006
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 8
Reputation: AnG' is an unknown quantity at this point 
Solved Threads: 0
AnG' AnG' is offline Offline
Newbie Poster

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

 
0
  #5
Oct 21st, 2006
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'
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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