Help with some homework code

Hi guys, so I have this homework with a sensor that measure temp, humidity and pressure. We had been given this UML https://imgur.com/a/UiDV7gq . We have to implement theese classes: Temperature, Humidity, Pressure generateTemperature() / generateHumidity() / generatePressure() / readSensor() / IRoom for Living, Bedroom, Bathroom and Kitchen with the metods createRoom() / readRoom() / updateRoom() / deleteRoom() / collectRoomData() / viewRoomData().
Have no idea how to start, i didn't find anything useful yet, hope u can help me.

Thank you.
I've done this so far
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//ISensor.h
#ifndef ISensor_H
#define ISensor_H
class ISensor {
public:
    virtual double readSensor() const = 0;
};
#endif

//Temperature.h
#ifndef Temperature_H
#define Temperatur_H
#include<iostream>
#include "ISensor.h"
class Temperature : public ISensor
{
public:
    double readSensor() const {
        return generateTemperature();
    }
    
private:
    double generateTemperature()const {
        int temperature;
        srand((int)time(NULL));
        temperature = -40 + (rand() % 120);
        return temperature;
    }
    
};
#endif 

//Humidity.h
#ifndef Humidity_H
#define Humidity_H
#include <iostream>
#include "ISensor.h"
class Humidity :public ISensor
{
public:
    double readSensor()const {
        return generateHumidity();
    }

private:
    double generateHumidity()const {
        int humidity;
        srand((int)time(NULL));
        humidity = 1 + (rand() % 100);
        return humidity;
    }
};
#endif

//Presure.h
#ifndef Presure_H
#define Presure_H
#include <iostream>
#include "ISensor.h"
class Presure :public ISensor
{
public:
    double readSensor()const {
       return generatePresure();
    }

private:
    double generatePresure()const {
        int presure;
        srand((int)time(0));    
        presure = 300+ (rand() % 800);
        return presure;
    }
};
#endif

//IRoom.h
#ifndef IROOM_H
#define IROOM_H

class IRoom {
public:
    virtual void readRoom() const = 0;
    virtual void createRoom() const = 0;
    virtual void updateRoom() const = 0;
    virtual void deleteRoom() const = 0;
};
#endif // !IROOM_H

//Living.h
#ifndef LIVING_H
#define LIVING_G
#include"IRoom.h"
#include"ISensor.h"
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
class Living :public IRoom {
public:
    void createRoom() const{
        ofstream Myfile("Living.txt");
    }
    void updateRoom()const {
        ofstream out;
        out.open("Livinf.txt", ios::app);


    }
    void deleteRoom() const{
        remove("Living.txt");
    }
    void readRoom() const{

    }
private:
    vector<ISensor> sensors;

};
#endif 
The UML diagram is unnecessarily complicated. A House/Room/Sensor combination is all that's required along with a few separate interface components and <vector> data storage.

Aside from that you need to have a clear understanding of what the system is supposed to do - I am assuming (f-last words) that it generates data input/manages it - with flexibility for adding componets to rooms in different houses.

Of course it might be a real estate or franchised sensor hardware shop - who knows?
> #ifndef Temperature_H
> #define Temperatur_H
Spelling is important.

> srand((int)time(0));
Do this once (and only once) at the start of main()
Calling srand() multiple times in the same second makes the result of rand() decidedly non-random.

Your classes seem fine from an overview.
But where do the files come into it in the room?
I would have guessed that readRoom would involve some use of readSensor for each of the sensors stored in the vector.

Thank you for responses, so the requirment was(translated): Write a C ++ application that implements the case monitoring system according to the UML diagram and specifications. To test the program, imagine a home that has at least one room in each of the 4 types, and several sensors are installed in each room, but at least one of the 3 types.

And gave us 3 files, one with UML and instructions, one for pressure and one for humidity and temperature(we have been given BMP280 and AM2320 I see that they are popular).
I will attach if needed for more info. And for the data it says like this:
"The generateTemperature () / generateHumidity () / generatePressure () methods generate a random number in the range [min, max] given by the sensor-specific datasheet: temperature (˚C), humidity (%), and pressure (hPa) ;"
It sounds strange that you have specific components and yet so far no mention of a microcontroller or other hardware. The point being, except for data ranges, what's the intent behind supplying the datasheets?

Anyway these have demos:

https://learn.adafruit.com/adafruit-am2320-temperature-humidity-i2c-sensor/arduino-usage

https://learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout/arduino-test
I know, I only got them as an example, we don't have any hardware, just to code and that was the problem, I only find code from ppl that actually use the hardware. Idk I will go with this bit of code.
Keywords like "imagine" and "generate a random number" suggest it's an entirely software simulation of some kind.
The UML diagram is pretty and all, but what are the various methods supposed to actually do? For example, what does LivingRoom::createRoom() do? I assume readRoom() reads info about the room, but from where? Is the deleteRoom() method really just the destructor for the class? It's hard to know exactly what these classes should do without the details.
Let the interrogation continue - so far we know it's some sort of a system that's supposed to do something. However, we know a little bit - and enough to allow @OP to proceed :)

So, in the interests of helping with the first steps, @OP needs to:
1. fix up the typos and the srand stuff etc @salem mentions above, then
2. start writing a simple main() and create a room and a sensor. Just one of each putting the sensor in the room vector.
Topic archived. No new replies allowed.