Last active
March 13, 2019 09:35
-
-
Save sodabear/73c8a4cf9bace54cb393c84ef0e96be0 to your computer and use it in GitHub Desktop.
CashRegister
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
#include <iostream> | |
#include <string> | |
using namespace std; | |
class CashRegister { | |
// used only one item | |
void checkout(int cash){ | |
} | |
// first parament is the quantity, second is price | |
void checkout(vector<int> numberOfItems, vector<int> listOfItems){ | |
} | |
} |
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
//第二版,我还没run,你run一下 | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
class CashRegister { | |
// used only one item | |
public : | |
int checkout(int cash){ | |
return cash; | |
} | |
// first parament is a list of quantities, second is a list of prices | |
// assume the lenght of numberOfItems and listOfItems are equal. | |
public : | |
int checkout(vector<int> numberOfItems, vector<int> listOfItems){ | |
int total = numberOfItems.size(); // | |
cout << "total : " << total; | |
int ans = 0; | |
for (int i = 0 ; i < total ; ++i){ | |
ans = ans+ numberOfItems[i]*listOfItems[i]; | |
} | |
return ans ; | |
} | |
}; | |
//Testing your method here | |
int main() { | |
// Declare an object of class Cash Registers | |
CashRegister obj1; | |
// testing checkout one item | |
int ans1 = obj1.checkout(5); | |
cout << "should be 5 " << ans1; | |
// testing checkout list of items | |
vector<int> customerItems; | |
customerItems.push_back(1); | |
customerItems.push_back(2); | |
vector<int> ItemsPrice; | |
ItemsPrice.push_back(100); | |
ItemsPrice.push_back(200); | |
int ans2 = obj1.checkout(customerItems, ItemsPrice); | |
cout << "should be 500 " << ans2; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment