You are here:

C++/C++ Question

Advertisement


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.



Thanks

Answer
#include <string>
#include <iostream>

class Label  {
   std::string name;
   std::string address1;
   std::string address2;
   std::string city;
   std::string state;
   std::string zip;
public:
   void print() {
      std::cout << "Name: " << name << "\n"
         << "Address: " << address1 << "\n";
   }
};

Please spend some time in learning C++. You could read Bruce Eckel's ebook "Thinking in C++", which also has a print version.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Amit Kumar

Expertise

I can answer Cplusplus language and library questions, including STL, ACE, Boost. I have a good background in Mathematics.

Experience

Programming in CPP for about 8 years. Industry experience of 4 years.

Education/Credentials
Bachelors and Masters in Computer Science from Indian Institute of Technology Delhi.

©2016 About.com. All rights reserved.