You are here:

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.


Hi Krista!

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:
class Address
     /* 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.



All Answers

Answers by Expert:

Ask Experts


Sean Wcisel


I can answer most beginner and intermediate level questions. My strengths are various algorithms and data manipulation. My background might be best suited to anything from basic CPP and file I/O, to algorithms involving recursion, hashing, binary search trees, and so on. I've done some tutoring in my free time, both online and in person. I also have quite a bit of debugging experience. I have some experience with game code, specifically using D3D based game engines. I only speak English, but I believe I do so very well :). I'm completely unable to answer questions about coding drivers for hardware, and many library specific issues.


I've studied CPP for roughly four years now, with a combined eight years of object oriented programming experience. I have worked professionally in the field for about a year. I have also had some tutoring experience in CPP and C#

IEEE, Western Michigan University Computer Club

Western Michigan University

©2016 All rights reserved.