Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 (35 points) Implement an Interface:In part 1 you will implement an interface provided in this handout for a simple Abstract Data Type (ADT)called

Part 1 (35 points) Implement an Interface:In part 1 you will implement an interface provided in this handout for a simple Abstract Data Type (ADT)called a Container. The interface has two private member variables, a stack allocated generic array and an integer size. The ADT must pass your own confidence tests submitted with your implementation in a file namedA01.cpp. Refer to the incomplete example confidence tests provided indriver.cpp. Be advised that assignments that do not compile and run will not be graded. Refer to the lecture slides, course-textbook, and supplemental reading regarding C++ classes and tem-plate programming. Implement the generic Container type using C++stem plating mechanism. Use the inclusion method for template programming by placing the member template definitions and the Container template declaration in a single file calledContainer.hpp. The Container type will have the functionality as provided in the interface shown on pages 2 & 3 of this handout. Implement only theempty, madd_item, get_item, remove_item methods. A Container object is instantiated with a datatype and a value argument. For example, the decla-ration for a ten element container of std::string elements is Container. The valueargument,10in the previous example, must be a constant expression. To access the instance type of a Container from a Container object, a value type alias is provided in the implementation. To support modern C++s range based for looping mechanism, the begin and end methods are provided. For more details about how to implement the interface refer to the example usage and sample output onpage4of this handout. Much of the code is provided for convenience to assist with the first assignment. Submit one ziparchive file namedA01.zipthatcontains yourA01.cpp & Container.hppsource files. Submit only source files and no binary files, project files, or solution files. Do not use any other name or else points will be deducted. Submitting the Assignment Include your name, your student id, the assignment number, the submission date, and a program de-scription in comments at the top of your files. Use any programming style you like (e.g. camelCase,iHungarianNotation, TitleCase, snakecase, etc.) but be consistent. Submit the assignment on Canvas(https://online.smc.edu) by uploading your .zip file to the Assignment 1 entry as an attachment. Do not cut-and-paste your program into a text window. Do not hand in a screenshot of your programs output. Do not hand in a text file containing the output of your program. Saving your work Save your work often (e.g., GoogleDrive, Microsoft OneDrive, Canvas, etc.). Always save a personal copy of your files (e.g. .cpp, .h, etc.). Do not store files on the virtual lab computers. TheContainerinterface is described below.

Place the interface and implementation in a single file named Container.hpp: //// Name: Your First Name & Last Name// SSID: Student ID Number// Assignment #: 1// Submission Date: 3/9/21//#ifndef _CONTAINER_HPP#define _CONTAINER_HPP#include #include template class Container{public:using value_type = T;void add_item(T item); // output container full , if add_item cannot addT get_item(int index ); //throw a string if index out of boundsvoid remove_item(T item); // remove first occurrence of itembool empty (); // check of Container is emptyvoid clear (); // clear all contents , assign value_typeconstexpr int size (); // return current number of elements in containerT* begin ();T* end();private:int _size = 0;T container[N];};// Container interface /* Sample Template member function definitions */template constexpr int Container :: size (){ return _size ;}template void Container :: clear (){for (int i = 0; i < _size; i++)container[i] = T(); //or value_type ();_size = 0;}template T* Container :: begin (){ return _size ? &container [0] : nullptr ;}template T* Container ::end(){ return begin () + _size ;}//// TODO: implement add_item ,get_item ,remove_item , empty//#endif Example tests of the Container type. Place in a file named A01.cpp#include #include #include "Container.hpp"int main (){std::cout << " ******************* Test 1******************* ";std::cout << "Testing Container ";Container container_of_strings;std::cout << "Testing Container :: add_items () {Green , Red , Black} ";container_of_strings.add_item("Green");container_of_strings.add_item("Red");container_of_strings.add_item("Black");std::cout << "Testing Container ::range -based -for -loop () ";for (auto& str : container_of_strings)std::cout << str << " ";std::cout << " Testing Container :: remove_item(Red) ";container_of_strings.remove_item("Red");std::cout << "Testing Container ::range -based -for -loop () ";for (auto& str : container_of_strings)std::cout << str << " ";std::cout << " Testing Container :: size () ";std::cout << "container_of_strings.size ()=" << container_of_strings.size() << " "; td::cout << " ******************* Test 2******************* ";std::cout << "Testing Container :: add_item (){0 ,2 ,4 ,... ,64 ,81} ";Container container_of_ints;for (int i = 0; i < 10; i++)container_of_ints.add_item(i * i);std::cout << "Testing Container ::range -based -for -loop ";for (auto num : container_of_ints)std::cout << num << " ";std::cout << " Testing Container :: remove_item (16) ";container_of_ints.remove_item (16);std::cout << "Testing Container ::range -based -for -loop ";for (auto num : container_of_ints)std::cout << num << " ";std::cout << " Testing Container :: clear () ";container_of_ints.clear ();std::cout << "Testing Container :: empty () ";std::cout << "container_of_ints.empty() is " << (container_of_ints.empty() ? "True" : "False")<<" ";std::cout << " ***** Test completed , enter any key to exit ******* ";char s; std::cin >> s;return 0;} Example output from tests:*******************Test 1*******************Testing ContainerTesting Container::add_items() {Green, Red, Black}Testing Container::range-based-for-loop()Green Red BlackTesting Container::remove_item(Red)Testing Container::range-based-for-loop()Green BlackTesting Container::size()container_of_strings.size()=2*******************Test 2*******************Testing Container::add_item(){0,2,4,...,64,81}Testing Container::range-based-for-loop0 1 4 9 16 25 36 49 64 81Testing Container::remove_item(16)Testing Container::range-based-for-loop0 1 4 9 25 36 49 64 81Testing Container::clear()Testing Container::empty()container_of_ints.empty() is True*****Test completed, enter any key to exit*******

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

How does a freemium business model work?

Answered: 1 week ago