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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!