C++/C++ Basic Question
I am majoring in computer science and I am new to it. If you could help me with this simple, simple question.
Q.) Create a C++ class that prints out address labels in which an individual label consists of a name, two address lines, a city, state, and zip code. For this plan, list the data items and a set of methods that would be useful for such a program. It says to chose your own class name and data item names.
Starting with C++ can be stressful, I hope I can give you a hand. I don't think your professor would want me to give you the whole solution, but let's see what we can do:
Remember that C++ is an object-oriented language, so we can think for an address as an object. Our data items are things that are part of all things that we consider an "address", like the city, state, etc. Also recall that methods are things that the address can do, in this case we'll probably only need a constructor and a print function.
You probably already knew all of that, but it never hurts to recap the basics, right? :). Okay, here's some problem-specific info (I'll give you mostly pseudo-code, so it won't compile, but you'll be able to use it to form your code).
Be sure to include both of the following:
#include <iostream> (needed for cout, etc.)
using namespace std; (your teacher will explain this later)
Here's a prototype for your class:
/* All your class variables go here, they'll probably all be strings. We're making them public so that they can be accessed easily by our print function */
void Address(Put your variables here)
/* Here's where you'll allocate your input variables to the variables in your class */
void Print() //I'm assuming this is defined in your header
/* This is where we're going to output our data. I'm assuming here that you'll just want cout calls to output everything to the screen. If you needed to output to a file, or directly to a printer, this would be much harder For example, "cout << State << endl;" would print a state name, followed by an end line, assuming that's what you wanted */
I hope all of that was clear enough. Let me know if you need help with syntax. Remember that in your main function you'll need to include the header for your address class, then create an item of that class, and call its print function via ItemName.Print();
Anyway, let me know if there's anything else I can do for you.