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 #5
#include<iostream>
#include<vector>
..
using namespace std;
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 HERESolution
A mailbox is an abstract date type capable of containing a number of messages of variable size defined by the following C/C++ structure:–
struct msg {
    int iFrom; /* who sent message (0 .. number-of-threads) */
    int type; /* its type */
    int num; /* number of items in payload (0 .. MAXPAYLOAD) */
    long payload[MAXPAYLOAD]; /* payload, an array of long */
 };
SendMsg(msg &Msg)  // Msg is reference to message to be sent;
                    // blocks if mailbox is full
 RecvMsg(msg &Msg)  // Msg is reference to area to store
                   // received message; blocks if mailbox
                    // is empty
Mailbox(int size)  // Constructor for mailbox of size bytes
 ~Mailbox()         // Destructor of mailbox
SendMsg(int iTo, struct msg *pMsg)      // msg as ptr
 /* iTo - mailbox to send to */
 /* pMsg - message to be sent */
RecvMsg(int iFrom, struct msg *pMsg) // msg as ptr
 /* iFrom - mailbox from which to get messages */
 /* pMsg - message structure to fill with received message */
CreateMailbox(int size) // routine to create and initialize
 DestroyMailbox() // routine to deallocate and destroy

