Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program Specifications This is to implement an application to be used by Custome

ID: 3920336 • Letter: P

Question

Program Specifications

This is to implement an application to be used by Customer Service representatives at a Wireless Phone Carrier to keep track of customers’ SmartPhone message usages/charges and to provide account disconnect service.

Messages can be sent from one SmartPhone account to another SmartPhone account. They can be one of the following types: Text message, Voice message, or Media message. Each message will be charged at different rates.

The assignment basically illustrates the following concepts:

Upon start up your program should show the below menu:

                                FOOTHILL WIRELESS   <OR A NAME OF YOUR CHOCE>   

                         MESSAGE UTILIZATION AND ACCOUNT ADMIN

Data Structures Specs

Since searching an account will be done frequently the ideal data structure for this application will be a STL map of SmartPhone accounts with phone numbers as the keys and vectors of pointers to Messages as their values.

Class Design

NOTE: For SearchMessage, EraseMessage, and DisconnectAccount use a try/catch block in each function. In the try block if an account is not found or if a message is not found throw an exception with error message describing what has gone wrong. In the exception handler (the catch block) simply display the error message and return.

Implementation Requirements

Main Program

Sample Output for listing all accounts

       Phone number         Total messages         Text   Voice   Media    Total charges

       310-290-1666                 3                          3            0            0          $ 18.90

       408-235-1500                 10                        3            3            4          $    0.00

       408-462-7890                 9                          4            2            3          $    2.75

Assignment submission and late policy: similar to previous assignments

Testing

Code Helper

Since you’ve been mastering the art of text file readings from previous two assignments it's not required to do anymore text file reading. Instead you can manually initialize the account map as shown below:

Account

Text

Voice

Media

650-267-1289

1

1

1

408-235-1500

3

3

4

650-781-7900

2

0

3

415-298-2162

0

1

1

945-890-5913

0

0

0

408-720-0012

1

4

0

650-230-9912

0

0

3

408-462-7890

4

2

3

415-902-9581

1

2

2

310-290-1666

3

0

0

void SmartCarrier::Init {

    // The below code shows how to manually add different kinds of messages to the map

      // You must add the accounts in the order given by the above table, row by row

     // std::map will take care of inserting the account in the right order

      // Assuming the STL map is named accounts_map

      // 1. Add Text

      Message *   text_message = new TextMessage ("650-267-1289", "650-345-9001", "Do you want to learn how to program in C++?");

      accounts_map ["650-267-1289"].push_back (text_message);

     // 2. Add Voice

     Message *   voice_message = new VoiceMessage ("650-267-1289", "408-111-2222", 120);    // Voice length of 120 seconds

      accounts_map ["650-267-1289"].push_back (voice_message);

     // 3. Add Media

      Message *   media_message = new MediaMessage ("310-777-8888", "650-267-1289", 25) ;   // media size of 25 MB

      accounts_map ["650-267-1289"].push_back (media_message);

}

Account

Text

Voice

Media

650-267-1289

1

1

1

408-235-1500

3

3

4

650-781-7900

2

0

3

415-298-2162

0

1

1

945-890-5913

0

0

0

408-720-0012

1

4

0

650-230-9912

0

0

3

408-462-7890

4

2

3

415-902-9581

1

2

2

310-290-1666

3

0

0

Explanation / Answer

ANSWER:

If you want to send SMS messages from your C++ application, first you need to connect your software and an SMS gateway to each other. Why? Because your application let you compose the SMS messages (including the text, the recipient’s phone number, etc.), but if you want to send out the SMS, you need to connect to the SMSC (Short Message Service Center that stores, forwards, converts and delivers SMS messages). An SMS gateway is able to connect to the SMSC of the Mobile Service Provider via SMPP IP SMS connection or a GSM modem, so actually the SMS gateway can send out your message. To establish connection between the SMS gateway and the C++ application, I used HTTP requests and responses. For sending SMS messages through HTTP, your SMS gateway should have a built-in webserver .

CODE :

#include<iostream>
#include<sstream>
#include<windows.h>
#include<wininet.h>

using namespace std;

string encode(string url);

int main(int argc, char** argv)
{
// the SMS gateway's host
// and port
string host       = "localhost";    
int port          = 9502;

// username
// and password
string username   = "admin";        
string password   = "abc123";

// message
string message    = "This is a test SMS.";

// originator's phone number
string originator = "+44555555555";   

// recipient's phone number.
// to send the SMS to multiple recipients, separate them by using commas without spaces
string recipient = "+44333333333";   

// preparing the HTTPRequest URL
stringstream url;
url << "/api?action=sendmessage&username=" << encode(username);
url << "&password=" << encode(password);
url << "&recipient=" << encode(recipient);
url << "&messagetype=SMS:TEXT&messagedata=" << encode(message);
url << "&originator=" << encode(originator);
url << "&responseformat=xml";

// create socket
HINTERNET inet = InternetOpen("Ozeki", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

// open connection and bind it to the socket
HINTERNET conn = InternetConnect(inet, host.c_str() , port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

// open the HTTP request
HINTERNET sess = HttpOpenRequest(conn, "GET", url.str().c_str(), "HTTP/1.1", NULL, NULL, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);

    // check errors
int error = GetLastError();
if(error == NO_ERROR)
{
// send HTTP request
HttpSendRequest(sess, NULL, 0, NULL,0);

// receive HTTP response

int size = 1024;
char *buffer = new char[size + 1];
DWORD read;
int rsize = InternetReadFile(sess, (void *)buffer, size, &read);
string s = buffer;
s = s.substr(0, read);

// check status code
int pos = s.find("<statuscode>0</statuscode>");

// if statuscode is 0, write "Message sent." to output
// else write "Error."
if(pos > 0) cout << "Message sent." << endl;
else cout << "Error." << endl;
}

system("pause");
}


// encoding converts characters that are not allowed in a URL into character-entity equivalent
string encode(string url)
{
char *hex = "0123456789abcdef";
stringstream s;

for(unsigned int i = 0; i < url.length(); i++)
{
byte c = (char)url.c_str()[i];
if( ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9') ){
s << c;
} else {
if(c == ' ') s << "%20";
else
s << '%' << (hex[c >> 4]) << (hex[c & 15]);
}
}

return s.str();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote