Created
October 3, 2016 09:41
-
-
Save bitmorse/d9c05762e7bccf164f217668880a58d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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