C Introduction to Programming It is short and simple practic

C++ Introduction to Programming

It is short and simple practice.

Classes: members and methods

Please solve #3, 4, 5.

#include<iostream>

#include<vector>

..

using namespace std;

3. Here is a definition of a class for dogs, and a class for dog owners class dog { public: string name; int age; string color; 1; class owner 1 public: string name; string address; vector«dog» dogs-owned; 1; Write a main function that will a) Create a variable named owner1 of type owner b) Set owner!\'s name to your own name c) Set owner1.\'s address to \"123 Example st., Nowhere CA 90001\" d) Give ownerl a dog named \"Wursty\", age 3, color brown d) Give ownerl a second dog named \"JJ Wiener\", age 5, color red YOUR ANSWER HERE 4. Using the same class structure as the previous problem, write functions void print_owner(owner o); and void print_dog(dog d); that will print all the details of an owner or dog to cout, \" Note that when printing an owner, one of the details that should be printed is all the dogs owned by that person! Test your code by adding it to the main you wrote for the previous problem, to print out the details of owner1. void print_owner (owner o) [ YOUR ANSWER HERE void print dog( dog o) f YOUR ANSWER HERE 5. Consider an application that maintained \"mailboxes\" for users. Each user has their own mailbox, and each mailbox can hold any number of (string) messages. Sketch a set of class definitions that could be used to represent users, mailboxes, and messages YOUR ANSWER HERE

Solution

All necessary function and main method is written:Please comment about code:

=================================================================

#include<bits/stdc++.h>
using namespace std;

class dog
{
public:
   string name;
   int age;
   string color;
};

class owner
{
public:
   string name;
   string address;
   vector<dog> dog_owned;
};
void print_dog(dog dog_owned)
{
  
       cout<<\"Name \"<<dog_owned.name<<endl;
       cout<<\"Age \"<<dog_owned.age<<endl;
       cout<<\"Color \"<<dog_owned.color<<endl;
}
void print_owner(owner o)
{
   cout<<\"Name :\"<<o.name<<endl;
   cout<<\"Address :\"<<o.address<<endl;

   cout<<\"Details of Dogs owned by \"<<o.name<<endl;

  
   for(int i=0;i<o.dog_owned.size();i++)
   {
       cout<<\"Details of Dog \"<<i+1<<endl;
       print_dog(o.dog_owned[i]);
   }
}
int main()
{
   owner owner1;
   owner1.name=\"Akshay\";
   owner1.address=\"USA\";

   dog d1,d2;
  
   d1.name=\"Wrusty\";
   d1.age=3;
   d1.color=\"Brown\";

   owner1.dog_owned.push_back(d1);
   d2.name=\"JJ Wiener\";
   d2.age=5;
   d2.color=\"Red\";
   owner1.dog_owned.push_back(d2);
   print_owner(owner1);
}

C++ Introduction to Programming It is short and simple practice. Classes: members and methods Please solve #3, 4, 5. #include<iostream> #include<vector
C++ Introduction to Programming It is short and simple practice. Classes: members and methods Please solve #3, 4, 5. #include<iostream> #include<vector

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site