Unlike c other programming languages have associative

Assignment Help C/C++ Programming
Reference no: EM13347710

Unlike C++, other programming languages have associative arrays that allow array indices to be strings instead of just integers.  You are to create a template class, SVector, that implements a constructor, push_back, [], and pop_back, with STL strings as indices.  push_back() takes two parameters, first the index string, and second the value stored.  You will store the value in an STL vector, and use an STL map to provide a mapping between the STL string indices and their corresponding integer indices.  Since the map will always contain a string and int you should typedef it.

1.  main().  Your main() will be quite long because it is the only function in main.cpp.

1.1. All exceptions should be caught and reported in main() relying on printing the value returned by what().

1.2. You must specify the exact exception you are catching, and may not use the elipse (...) in your catch.

1.3. You should declare a pointer to a SVector of type <int> so that you can call its constructor within a try-catch statement and still have scope for the whole main function.

2.  Operation Files

2.1. Your program should open and read the file specified by the first command line argument of the program.

2.2.  The first line of the file contains an integer that indicates the size with which to construct the SVector.  Your program should catch the STL exception thrown by the STL vector class in main(), and report it before terminating.

2.3.  Each line of the file starts with a char.

2.3.1.  If the char is a 'U', then there is an integer followed by a string on the line with which to call push_back.

2.3.2.  If the char is an 'A', then it is followed by a string with which to access the SVector using [].  Your program should print out the corresponding integer, or throw an exception if the string is an invalid index.

2.3.3.  If the char is an 'O', then it is followed by nothing.  Normally, your main() should print nothing, but it should catch the exception if the vector is empty.  Your SVector::pop_back() should update the map so the string to int mapping is removed.  This is a little tricky, since you have only the int from the vector size() with which to work.

3.  Exceptions.  Your SVector class should throw four exceptions:

3.1.  If the constructor size is invalid, then it will just allow the implicit STL bad_alloc exception to pass up to main().

3.2.  If the string index is invalid, then it should explicitly throw an STL range_error exception.

3.3.  If the SVector is empty when a pop_back is called because the vector is empty, then it should throw an underflow exception of the STL.

3.4.  If the string used for push_back is a duplicate then your class will throw an exception of a class named Whoops that you write in SVector.h that has a constructor, and a what() method.

3.5. Your function definitions should indicate what type of exception they throw.

3.6. You can find information about the STL exceptions at:

3.7.  assert

3.7.1.  You must add assertions that would catch the three explicit SVector exceptions of 3.2, 3.3, and 3.4 before they reach the throw statements.

3.8. Makefile

3.8.1.  Your Makefile should have a "all:" rule that compiles both p8.out with the NDEBUG defined using the D option of g++, and p8b.out that compiles without NDEBUG defined so that the asserts will work.

3.8.2.  You need not compile a mainB.o file for this assignment, so only two lines are needed to create each executable.

3.9.  Further specifications

3.9.1.  All implementation code for Whoops and SVector must be in SVector.cpp.

3.9.2.  Remember to use const wherever appropriate.

Reference no: EM13347710

Questions Cloud

The corporate finance projectname of the company netflix1 : the corporate finance projectname of the company netflix1. leverage and coverage ratiosnbspmost recent fiscal
Bull write a blog article for a coding and technical : bull write a blog article for a coding and technical community blog.bull the length of the article is to be between 500
Problem 1evaluate whether the following statements are true : problem 1evaluate whether the following statements are true or falsebull as long as buyer are willing to pay a
Description in the process of processor development : description in the process of processor development functional verification is a crucial step that must be conducted
Unlike c other programming languages have associative : unlike c other programming languages have associative arrays that allow array indices to be strings instead of just
1 identify and explain the weakness in lehmans governance : 1. identify and explain the weakness in lehmans governance practices.a. what was the quality of the reporting to the
Prepare a program for a company named retail-martbullprompt : prepare a program for a company named retail-mart.bullprompt the user to enter an item name one word only a quantity
Prepare a linux shell in other words write a cc program : prepare a linux shell in other words write a cc program that will recursively prompt for input from the user. the shell
Question 1 two friends joe and bill both have carpentry : question 1 two friends joe and bill both have carpentry skills and decide to go into business as partners together

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program in c that will find smallest value

Write a programe c that will find the smallest, largest and average values in a collection of N numbers.Get the value of N before scanning each value in the collection of N numbers.

  Prefetching is a technique that leverages predictable

Prefetching is a technique that leverages predictable address patterns to speculatively bring in additional cache blocks when a particular cache block is accessed. One example of prefetching is a stream buffer that prefetches sequentially adjacent..

  Define a base class to use for the entire program

Your company, Datamax, Inc., is in the process of automating its payroll systems. Your manager has asked you to create a program that calculates overtime pay for all employees.

  Write a program that creates an arraylist

Write a program that creates an ArrayList and adds a Loan Object, a Date Object, a string, JFrame object, and a circle object to the list, and use a loop to display all the elements in the list by invoking the object's toString() method.

  Find the sixth maclaurin polynomial for sin x

Find the sixth Maclaurin polynomial for sin x and use Chebyshev economization to obtain a lesser-degree polynomial approximation.

  Write a program in which the program print out the input

use (switch statement) to write a program in which the program print out the input (single character) if the character is not '2','t', or 'w'. Use 'default' and 'break' wisely.

  Class to act as a generic array

Create a class to act as a generic array (i.e. the user will be able to choose the data type to be stored by passing the appropriate template argument.

  Lu decomposition with gauss elimination

The LU decomposition with Gauss elimination and what is the physical interpretation of the elements of ? Write C++ programs for steps 2, 3, and 4.

  Ohio phonebook has gotten mixed up

In an accident, the Ohio phonebook has gotten mixed up. The names are now really out of order. You and your enthusiastic, but naive, assistant Carl must fix the problem. No one can use the phonebook while you are sorting it, so every extra second of ..

  Develop a class airborne location

develop a class AirborneLocation that represents the location of airplanes with respect to a reference radar location. Each AirborneLocation object should include data member for aircraftID (integer),

  Our string class always deletes the old character

Our String class always deletes the old character buffer and reallocates a new character buffer on assignment or in the copy constructor. This need not be done if the new value is smaller than the current value

  Write a program to evaluate infix expressions

Write a program to evaluate infix expressions and summarize differences between array notation and pointer notation

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd