Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* exo2.cpp
*
* Created on: Oct 3, 2016
* Author: sam
*/
#include <vector>
#include <iostream>
using namespace std;
struct Enreg {
int stock;
double price;
vector<int> sales;
};
void reset(Enreg *enregStruct){
enregStruct->stock = 0;
enregStruct->sales.clear();
}
void display(Enreg *enregStruct){
cout << "Stock: " << enregStruct->stock << endl;
cout << "Price: " << enregStruct->price << endl;
cout << "Sales: ";
vector<int>::iterator pos;
for(pos = enregStruct->sales.begin(); pos != enregStruct->sales.end(); pos++){
cout << *pos << " ";
}
cout << endl;
}
void display(Enreg *enregStruct, int month){
cout << "Sales["<< month <<"]: ";
cout << enregStruct->sales.at(month) << endl;;
}
int main () {
vector<int> mystock_sales(12,4);
Enreg mystock = {200, 12, mystock_sales};
display(&mystock);
display(&mystock, 3);
reset(&mystock);
display(&mystock);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment