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

This is my sequence file. What I need to do is listed in the prompt below. I am

ID: 3769752 • Letter: T

Question

This is my sequence file. What I need to do is listed in the prompt below. I am having a very hard time properly using exceptional handling.

Additionally, you need to write a second client for this class called sequence_test2.cpp. It needs to be exactly the same as the sequence_test.cpp except that it must take in a different data type. You do not have to create a template for the client, just create a second .cpp and manually change the data type where necessary in that second .cpp file. When you complete this client, the project manager will be able to successfully use the sequence class with either the sequence_test.cpp or your new sequence_test2.cpp.  Note: You cannot include both clients simultaneously in the same project in your IDE. Swap them out for testing or create two separate projects. Note: You will need to make some minor changes to the sequence_test.cpp file to make it work with your templated class.

Add some exception handling added to the clients as needed. An exception should be thrown and handled in a catch block in the following situations:

If the user types in an invalid option for the menu

If the user types in something that is not a number

// FILE: sequence_test.cxx

// An interactive test program for the new sequence class

#include <cctype> // Provides toupper

#include <iostream> // Provides cout and cin

#include <cstdlib> // Provides EXIT_SUCCESS

#include "sequence1.h" // With value_type defined as double

using namespace std;

using namespace main_savitch_3;

// PROTOTYPES for functions used by this test program:

void print_menu( );

// Postcondition: A menu of choices for this program has been written to cout.

char get_user_command( );

// Postcondition: The user has been prompted to enter a one character command.

// The next character has been read (skipping blanks and newline characters),

// and this character has been returned.

double get_data( );

// Postcondition: The user has been prompted to enter a real number. The

// number has been read, echoed to the screen, and returned by the function.

int main( )

{

sequence<int> test; // A sequence that we’ll perform tests on

char choice; // A command character entered by the user

  

cout << "I have initialized an empty sequence of real numbers." << endl;

  

do

{

print_menu( );

choice = toupper(get_user_command( ));

switch (choice)

{

case 'C': cout << "Current is " << test.current() << '.' << endl;

break;

case 'S': cout << "Size is " << test.size( ) << '.' << endl;

break;

case 'A': test.attach(get_data());

break;

case 'P': test.showSequence();

break;

case 'R': test.remove_current( );

cout << "The current item has been removed." << endl;

break;

default: cout << choice << " is invalid." << endl;

}

}

while ((choice != 'Q'));

  

return EXIT_SUCCESS;

}

void print_menu( )

// Library facilities used: iostream.h

{

cout << endl; // Print blank line before the menu

cout << "The following choices are available: " << endl;

cout << " C Print the result from the current( ) function" << endl;

cout << " P Print a copy of the entire sequence" << endl;

cout << " S Print the result from the size( ) function" << endl;

cout << " A Attach a new number with the attach(...) function" << endl;

cout << " R Activate the remove_current( ) function" << endl;

cout << " Q Quit this test program" << endl;

}

char get_user_command( )

// Library facilities used: iostream

{

char response;

  

try {

  

cout << "Enter choice: ";

  

cin >> response; // Input of characters skips blanks and newline character

  

if(response != 'C' && response != 'P' && response != 'S' &&

   response != 'A' && response != 'R' && response != 'Q')

throw "User has entered an Invalid Option";

  

{

//bool isNum = true;

//for(int k = response; k != response; ++k)

// isNum &&= isdigit(*k);

//if(!isNum)

// throw "User has entered an Invalid Option";

// else throw "User entered a number";

}

   return command;

}

   double get_data( )

   // Library facilities used: iostream

{

double result;

  

cout << "Please enter a value for the sequence: ";

cin >> result;

cout << result << " has been read." << endl;

return result;

}

Explanation / Answer

Added try catch blocks.........

#include <cctype> // Provides toupper
#include <iostream> // Provides cout and cin
#include <cstdlib> // Provides EXIT_SUCCESS

using namespace std;
using namespace main_savitch_3;

// PROTOTYPES for functions used by this test program:
void print_menu( );
// Postcondition: A menu of choices for this program has been written to cout.

char get_user_command( );
// Postcondition: The user has been prompted to enter a one character command.
// The next character has been read (skipping blanks and newline characters),
// and this character has been returned.

double get_data( );
// Postcondition: The user has been prompted to enter a real number. The
// number has been read, echoed to the screen, and returned by the function.


int main( )
{
sequence<int> test; // A sequence that we’ll perform tests on
char choice; // A command character entered by the user
  
cout << "I have initialized an empty sequence of real numbers." << endl;
  
do
{
print_menu( );
choice = toupper(get_user_command( ));
switch (choice)
{
case 'C': cout << "Current is " << test.current() << '.' << endl;
break;
case 'S': cout << "Size is " << test.size( ) << '.' << endl;
break;
case 'A': test.attach(get_data());
break;
case 'P': test.showSequence();
break;
case 'R': test.remove_current( );
cout << "The current item has been removed." << endl;
break;
default: cout << choice << " is invalid." << endl;
}
}
while ((choice != 'Q'));
  
return EXIT_SUCCESS;
}

void print_menu( )
// Library facilities used: iostream.h
{
cout << endl; // Print blank line before the menu
cout << "The following choices are available: " << endl;
cout << " C Print the result from the current( ) function" << endl;
cout << " P Print a copy of the entire sequence" << endl;
cout << " S Print the result from the size( ) function" << endl;
cout << " A Attach a new number with the attach(...) function" << endl;
cout << " R Activate the remove_current( ) function" << endl;
cout << " Q Quit this test program" << endl;
}

char get_user_command( )
// Library facilities used: iostream
{
char response;
  
try {
  
cout << "Enter choice: ";
  
cin >> response; // Input of characters skips blanks and newline character
  
if(response != 'C' && response != 'P' && response != 'S' &&
response != 'A' && response != 'R' && response != 'Q')
throw "User has entered an Invalid Option";
  
{
//bool isNum = true;
//for(int k = response; k != response; ++k)
// isNum &&= isdigit(*k);
//if(!isNum)
// throw "User has entered an Invalid Option";
// else throw "User entered a number";
}
return response;
}
catch(const char n)
   {
       cout << " "<<n<<"is not a valid input";
   }
}
double get_data()
// Library facilities used: iostream
{
double result;
try{
cout << "Please enter a value for the sequence: ";
cin >> result;
if(!cin){
throw result;
}
cout << result << " has been read." << endl;
return result;
}
catch(const char n)
   {
       cout << " is not a valid input";
   }
}   

----------------------------------------------------------------------------------------------------------------------------------------------------

sequence_test2.cpp ********** with differrnt data types ***********
------------------------------------------------

#include <cctype> // Provides toupper
#include <iostream> // Provides cout and cin
#include <cstdlib> // Provides EXIT_SUCCESS

using namespace std;
using namespace main_savitch_3;

// PROTOTYPES for functions used by this test program:
void print_menu( );
// Postcondition: A menu of choices for this program has been written to cout.

int get_user_command( );
// Postcondition: The user has been prompted to enter a one character command.
// The next character has been read (skipping blanks and newline characters),
// and this character has been returned.

int get_data( );
// Postcondition: The user has been prompted to enter a real number. The
// number has been read, echoed to the screen, and returned by the function.


int main( )
{
sequence<int> test; // A sequence that we’ll perform tests on
int choice; // A command character entered by the user
  
cout << "I have initialized an empty sequence of real numbers." << endl;
  
do
{
print_menu( );
choice = toupper(get_user_command( ));
switch (choice)
{
case 1: cout << "Current is " << current() << '.' << endl;
break;
case 2: cout << "Size is " << size( ) << '.' << endl;
break;
case 3: attach(get_data());
break;
case 4: showSequence();
break;
case 5: remove_current( );
cout << "The current item has been removed." << endl;
break;
default: cout << choice << " is invalid." << endl;
}
}
while ((choice != 9));
  
return EXIT_SUCCESS;
}

void print_menu( )
// Library facilities used: iostream.h
{
cout << endl; // Print blank line before the menu
cout << "The following choices are available: " << endl;
cout << " 1 Print the result from the current( ) function" << endl;
cout << " 2 Print a copy of the entire sequence" << endl;
cout << " 3 Print the result from the size( ) function" << endl;
cout << " 4 Attach a new number with the attach(...) function" << endl;
cout << " 5 Activate the remove_current( ) function" << endl;
cout << " 9 Quit this test program" << endl;
}

int get_user_command( )
// Library facilities used: iostream
{
int response;
  
try {
  
cout << "Enter choice: ";
  
cin >> response; // Input of characters skips blanks and newline character
  
if(response != 1 || response != 2 || response != 3 ||
response != 4 || response != 5 || response != 9)
throw "User has entered an Invalid Option";
return response;
}
catch(const int n)
{
cout << " "<<n<<"is not a valid input";
}
}
int get_data()
// Library facilities used: iostream
{
int result;
try{
cout << "Please enter a value for the sequence: ";
cin >> result;
if(!cin){
throw result;
}
cout << result << " has been read." << endl;
return result;
}
catch(const char n)
{
cout << " is not a valid input";
}
}   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote