Create a template class

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

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: EM131643

Questions Cloud

The corporate finance project : The debt or equity ratio from I-Metrix is based on book values. If you were to evaluate the ratio on the basis of market values, could this ratio tend to be higher or lower than on the basis of book values?
Technical community blog : Write a blog article for a coding and technical community blog.
Economics of markets and organizations : Economics of Markets and Organizations
Processor development : Explain the process of processor development
Create a template class : Create a template class, SVector, that implements a constructor
Explain the weakness in lehman''s governance practices : Identify and explain the weakness in Lehman's governance practices.
Prepare a program for a retail-mart company : Prepare a program for a company Retail-Mart.
Prepare a linux shell : Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as
Types of partnership : Explain the different types of partnership that Joe and Bill might form.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write the code

Write a program that allows an instructor to keep a grade book. Each students has scores for exams, homework assignments, and quizzes.

  Public transport fare ticketing system

Implement and test a public transport fare ticketing system.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Computer programming techniques

Construct a program from a design and use appropriate functions

  Structured programming using procedural languages

A a program that is called "Playing with Numbers or Letters".

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Iterative programming problem solving approaches

Write a recursive function void reverse ( ) that reverse a sentence

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

  Write a c program that reads a data file of floating numbers

Write a program that reads a data file of floating numbers into an array and prints the array elements along with the number of items in the array

  Implementation of sorting technique

Implementation of sorting technique

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