Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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 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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9132074

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As