Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment tests the concepts of: Classes Proper object oriented design and usage of const namespace Program Objective: The following items class was not writen

  1. This assignment tests the concepts of:
    • Classes
    • Proper object oriented design and usage of const
    • namespace

Program Objective:

  1. The following items class was not writen with the best object oriented principals
  2. put the items class in the DS namespace (will not compile until you do)
  3. Add as many const keywords to the member and non-member functions of items, but the main driver should not require modification
  4. Change variables to static if you can
  5. Mitigate compile warnings
  6. The output should not change
  7. No need to add any inline functions

DELIVERABLES:

Description filename
Your fixed header of items items.h
Your fixes implementation of items items.cpp

You should not modify main.cpp.

Submitted assignments without the above file named correctly will render your assignment as uncompilable and will be detrimental to your assignment grade.

Example output (from multiple runs with different arguments given):

42 50 530 530 false false true

Files

main.cpp

#include  #include  #include "items.h" using namespace std; using namespace DS; int main() { items a; items b(50); items c(b); items *p = &b; cout << a << endl; cout << b << endl; a.set("apple"); b.set(530); cout << a << endl; cout << b << endl; cout << boolalpha << a.same(&b) << endl; cout << boolalpha << a.same(&c) << endl; cout << boolalpha << b.same(p) << endl; return 0; }

items.h

#ifndef LAB_CONST_ITEMS_H #define LAB_CONST_ITEMS_H #include  #include  class items { public: items(); items(int); items(items&); int get() { return current; } void set(int); void set(std::string s); bool same(items*); private: const int everything = 42; int current; }; std::ostream& operator<<(std::ostream& out, items obj); #endif //LAB_CONST_ITEMS_H

items.cpp

#include "items.h" items::items() { set(everything); } items::items(int i) { set(i); } items::items(items& i) { set(i.get()); } bool items::same(items *p) { return this == p; } void items::set(int i) { current = i; } void items::set(std::string s) { if (s.length() > 0) { current = s.at(0); for (int i = 1; i < s.length(); ++i) current += s.at(i); } else current = everything; } std::ostream &operator<<(std::ostream &out, items obj) { out << obj.get(); return out; }

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_2

Step: 3

blur-text-image_3

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

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions