Skip to content

Instantly share code, notes, and snippets.

@bitmorse
Created October 3, 2016 09:41
Show Gist options
  • Save bitmorse/d9c05762e7bccf164f217668880a58d8 to your computer and use it in GitHub Desktop.
Save bitmorse/d9c05762e7bccf164f217668880a58d8 to your computer and use it in GitHub Desktop.
/*
* 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