100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Csc01b1 $9.23   Add to cart

Exam (elaborations)

Csc01b1

 2 views  0 purchase
  • Course
  • Institution

This is a computer science practical for first year

Preview 2 out of 12  pages

  • October 28, 2023
  • 12
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
avatar-seller
1 #ifndef IIOTMONITOR_H
2 #define IIOTMONITOR_H
3
4 #include <iostream>
5 #include "IIoTAdvancedScanner.h"
6 #include "IIoTSimpleScanner.h"
7
8 #include "CommonLibs.h"
9
10 using namespace std;
11
12 class IIoTSimpleScanner;
13 class IIoTAdvancedScanner;
14
15 class IIoTMonitor
16 {
17 public:
18 // Constructors and destructor.
19 IIoTMonitor();
20 IIoTMonitor(int, int, IIoTSensor, bool);
21 IIoTMonitor(const IIoTMonitor&);
22 ~IIoTMonitor();
23
24 // Member function for producing a string representation of the IIoT environment.
25 string toString() const;
26 // Member function for scanning the IIoT environment.
27 // Boolean parameter, true use Advanced Scanner, false use Simple Scanner
28 void scan();
29
30 // Accessor member functions.
31 int getRows() const;
32 int getCols() const;
33 IIoTSensor getSensor(int intRow, int intCol) const;
34
35 // Mutator member function.
36 void setSensor(int intRow, int intCol, IIoTSensor recSensor);
37
38 // Class constants.
39 static const int DEFAULT_HUMIDITY = 20;
40 static const int DEFAULT_ROWS = 50;
41 static const int DEFAULT_COLS = 50;
42 static const int NUM_SENSORPARTS = 5;
43 static constexpr double DEFAULT_PRESSURE = 20.0;
44 static constexpr double DEFAULT_LIGHT_INTENSITY = 5.0;
45 static constexpr double DEFAULT_TEMPERATURE = 10.0;
46
47 private:
48 // Helper (ancillary) functions.
49 void alloc(int, int, IIoTSensor, bool);
50 void clone(const IIoTMonitor& objOriginal);
51 void dealloc();
52 void setSensorData();
53 void enforceRange(int intValue, int intMin, int intMax) const;
54 int rangedRandom(int, int) const;
55 // Member variables (state).
56 IIoTScanner* _scanner;
57 //IIoTAdvancedScanner* _advancedScanner;
58 IIoTSensor** _sensors;
59 int _rows;
60 int _cols;
61 };
62
63 #endif // IIOTMONITOR_H_INCLUDED

, 1 #include "IIoTMonitor.h"
2 #include "IIoTScanner.h"
3 #include <cassert>
4
5 #include <sstream>
6
7 IIoTMonitor::IIoTMonitor()
8 : IIoTMonitor(DEFAULT_ROWS, DEFAULT_COLS, {DEFAULT_TEMPERATURE,
9 DEFAULT_HUMIDITY, DEFAULT_PRESSURE, DEFAULT_LIGHT_INTENSITY}, true)
10 {
11 }
12
13 IIoTMonitor::IIoTMonitor(int intRows, int intCols, IIoTSensor recSensor, bool advancedScanner)
14 {
15 // allocate memory
16 alloc(intRows, intCols, recSensor, advancedScanner);
17 // setSensorData
18 setSensorData();
19 }
20
21 IIoTMonitor::IIoTMonitor(const IIoTMonitor& objMonitor)
22 : IIoTMonitor(objMonitor._rows, objMonitor._cols, {DEFAULT_TEMPERATURE,
23 DEFAULT_HUMIDITY, DEFAULT_PRESSURE, DEFAULT_LIGHT_INTENSITY}, true)
24 {
25 // Make a deep copy
26 clone(objMonitor);
27 }
28
29 void IIoTMonitor::alloc(int intRows, int intCols, IIoTSensor recSensor, bool advancedScanner)
30 {
31 // Set Private Properties
32 _rows = intRows;
33 _cols = intCols;
34 // Allocate Memory for 2D Array
35 _sensors = new IIoTSensor*[intRows];
36 for(int r = 0; r < intRows; r++)
37 {
38 _sensors[r] = new IIoTSensor[intCols];
39 for(int c = 0; c < intCols; c++)
40 {
41 _sensors[r][c].dblTemperature = recSensor.dblTemperature;
42 _sensors[r][c].intHumidity = recSensor.intHumidity;
43 _sensors[r][c].dblPressure = recSensor.dblPressure;
44 _sensors[r][c].dblLightIntensity = recSensor.dblLightIntensity;
45 _sensors[r][c].blnActive = true;
46 //_sensors[r][c].numActive = NUM_SENSORPARTS;
47 }
48 }
49 // Initialize Scanner objects
50 if(advancedScanner){
51 _scanner = new IIoTAdvancedScanner;
52 }else{
53 _scanner = new IIoTSimpleScanner;
54 }
55 }
56
57 void IIoTMonitor::clone(const IIoTMonitor& objOriginal)
58 {
59 for(int r = 0; r < _rows; r++)
60 {
61 for(int c = 0; c < _cols; c++)
62 {
63 _sensors[r][c].dblTemperature = objOriginal._sensors[r][c].dblTemperature;
64 _sensors[r][c].intHumidity = objOriginal._sensors[r][c].intHumidity;
65 _sensors[r][c].dblPressure = objOriginal._sensors[r][c].dblPressure;
66 _sensors[r][c].dblLightIntensity = objOriginal._sensors[r][c].dblLightIntensity;

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller dzunimathe. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $9.23. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67232 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$9.23
  • (0)
  Add to cart