How to write the main function

//FuelFlowSensor.hpp
#include<iostream>
using namespace std;

class FuelFlowSensor{
public:
FuelFlowSensor(int time, int flow);

FuelFlowSensor();

int getTime() const;

void setTime (int time);

double getFlow() const;

void setFlow(double flow);
private:


int time;
double flow;

};
//FuelRecordStation.cpp
#include<iostream>
#include<vector>
using namespace std;

class FuelRecordStation{
public:
FuelRecordStation();
int getid() const;
void setid(int id);
const vector<int> &getReadings() const;
void setReadings(const vector<int> &readings);
int getLaunchDates() const;
void setLaunchDates(int launchDate);
const string &getPilpeline() const;
void setPilpeline(const string &pipeline);
const string &getSection() const;
void setSection(const string &section);
struct get_current{
string date();

string time();

string timeall();
}get_current;
void add_reading(vector<int> &reading,string current_time);

private:
int id;
vector<int> reading;
int launch_date;
string section;
string pipeline;
};
The main function looks like this
int main() {}
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either


With that said there are two forms the main function may take according to the standard:

int main () { body } and int main (int argc, char *argv[]) { body }.
https://en.cppreference.com/w/cpp/language/main_function

I suspect you really want to know how to use your class in main.
@OP
Here's a practical start. You will need to complete the class implementation parts but I have flagged a few to get you started and get some output using some dummy data in main.

Without a context for how the two classes are meant to interact, if at all, there's not much use in going further until you provide it.

However, one challenge is to create the vector of objects once you sort out the more basic class implementation stuff.

I wouldn't get too fussed about the esoterica of C++ and 'better ways' until you get what you have up and running.

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
//FuelFlowSensor.hpp
#include<iostream>
using namespace std;

class FuelFlowSensor{
public:
    FuelFlowSensor(int time, int flow){}; // <--
    FuelFlowSensor(){}; // <--
    
    int getTime() const;
    
    void setTime (int time);
    
    double getFlow() const;
    
    void setFlow(double flow);
private:
    int time;
    double flow;
    
};
//FuelRecordStation.cpp
#include<iostream>
#include<vector>
using namespace std;

class FuelRecordStation{
public:
    FuelRecordStation(){}; // <--
    int getid() const{return id;}// <--
    void setid(int ID){id = ID;}// <--
    const vector<int> &getReadings() const;
    void setReadings(const vector<int> &readings);
    int getLaunchDates() const;
    void setLaunchDates(int launchDate);
    const string &getPilpeline() const;
    void setPilpeline(const string &pipeline);
    const string &getSection() const;
    void setSection(const string &section);
    struct get_current{
        string date();
        
        string time();
        
        string timeall();
    }get_current;
    void add_reading(vector<int> &reading,string current_time);
    
private:
    int id;
    vector<int> reading;
    int launch_date;
    string section;
    string pipeline;
};

int main()
{
    FuelRecordStation FRS_1, FRS_2;
    
    int FRS_1_ID = 123;
    FRS_1.setid(FRS_1_ID);
    cout << FRS_1.getid() << '\n';
    
    FuelFlowSensor FFS_A(10, 100), FFS_B(20,110), FFS_C(11,212);
}


123
Program ended with exit code: 0
Topic archived. No new replies allowed.