Code Monkey home page Code Monkey logo

bop2_lab08's Introduction

Task1

Write a program for registering and storing computer devices. There are two types of devices: printers and displays.

Displays have an identification number (std::string), a price (double) and a year of appropriation (int).

Printers have an identification number (std::string), a price (double) and a printing speed (double).

Both devices are a type of device (IS_A relationship), so use a base class named Device. Common attributes should be in the base class.

The main function creates a heterogeneous container (array) for some number of devices, and then prints the devices' attributes. Add a print function to the base class as well as the subclasses. Does the base print function need to be virtual?

Decomposition of the program

  1. Device.h, Printer.h, Display.h: class declaration headers
  2. DeviceMain.cpp: main program

Task2

Add a sortDevices function to DeviceMain.cpp. This function should sort the devices array by the idNumber of the devices. Its signature should be:

void sortDevices(Devices* equipments[], int size)

You can use last week's sorting algorithm but with different types. A sorting algorithm requires a way to compare two elements of the sequence it is sorting. For this, it uses one of the comparison operators (<, >, <= or >=). You need to overload this operator in the Device class. Make sure that you are not comparing pointers.

Add at least 5 new device to the array and sort it before printing each element. Make sure that they are printed in alphabetical order.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.