Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<time.h>
- using namespace std;
- template<typename Tip>
- int countRuns(Tip *array, int size) {
- int counter = 0;
- for (int i = 0; i < size; i++) {
- if (array[i] == array[i + 1]) {
- counter++;
- while (array[i] == array[i + 1]) {
- i++;
- }
- }
- }
- return counter;
- }
- class Song {
- int mBpm;
- string mName;
- public:
- Song(): mBpm(0), mName("Unknown"){}
- Song(string name, int bpm) : mName(name), mBpm(bpm) {}
- friend ostream& operator<< (ostream&, const Song);
- Song* getSong() {
- Song array[10];
- for (int i = 0; i < 10; i++) {
- array[i] = Song();
- }
- return array;
- }
- friend bool operator== (const Song& s1, const Song& s2);
- };
- ostream& operator<< (ostream& izlaz, const Song song) {
- izlaz << song.mName << ", " << song.mBpm << endl;
- return izlaz;
- }
- bool operator== (const Song& s1, const Song& s2) {
- return s1.mBpm == s2.mBpm && s1.mName == s2.mName;
- }
- class MovieTheather {
- protected:
- int mTotalPlaces;
- int mOccupiedPlaces;
- double mTicketPrice;
- public:
- MovieTheather() : mTotalPlaces(0), mOccupiedPlaces(0), mTicketPrice(0){}
- MovieTheather(int totalPlaces, int occupiedPlaces, int ticketPrice) : mTotalPlaces(totalPlaces), mOccupiedPlaces(occupiedPlaces), mTicketPrice(ticketPrice){}
- MovieTheather(int totalPlaces, int ticketPrice) : mTotalPlaces(totalPlaces), mOccupiedPlaces(totalPlaces), mTicketPrice(ticketPrice) {}
- double getEarnings() { return mOccupiedPlaces * mTicketPrice; }
- bool isFull() {
- return mTotalPlaces == mOccupiedPlaces;
- }
- void buyTicket() {
- mOccupiedPlaces++;
- }
- double calculateTimeTillFull(int mTicketsPerHour) {
- int mPlacesToFill = mTotalPlaces - mOccupiedPlaces;
- return mPlacesToFill / mTicketsPerHour;
- }
- };
- int FindLastToFill(MovieTheather *array, int size, int mTicketsPerHour) {
- int maxIndex = 0;
- for (int i = 0; i < size; i++) {
- if (array[i].calculateTimeTillFull(mTicketsPerHour) > array[maxIndex].calculateTimeTillFull(mTicketsPerHour)) {
- maxIndex = i;
- }
- }
- return maxIndex;
- }
- void runExample() {
- MovieTheather theather(100, 2.50);
- if (theather.isFull()) cout << "No space left." << endl;
- else theather.buyTicket();
- }
- class LuxuryTheather : public MovieTheather {
- double mLuxuryTicketPrice;
- int mLuxuryPacket;
- public:
- LuxuryTheather(int totalPlaces, int occupiedPlaces, int ticketPrice, double luxuryTicketPrice, int luxuryPacket) : MovieTheather(totalPlaces, occupiedPlaces, ticketPrice), mLuxuryTicketPrice(luxuryTicketPrice), mLuxuryPacket(luxuryPacket){}
- virtual ~LuxuryTheather();
- virtual void buyTicket(bool isLuxuryPacket){
- if (isFull()) { cout << "No space left."; }
- else {
- mOccupiedPlaces++;
- if (isLuxuryPacket) {
- mLuxuryPacket++;
- }
- }
- }
- };
- class TicketException : public runtime_error
- {
- int mTicketNumber;
- public:
- TicketException(string message, int ticketNumber) : runtime_error(message), mTicketNumber(ticketNumber) {}
- int getTicketNumber()
- {
- return mTicketNumber;
- }
- };
- void buyTickets(LuxuryTheather *theather, int *tickets, int size) {
- try
- {
- srand(time(NULL));
- bool isLuxuryPacket;
- for (int i = 0; i < size; i++) {
- isLuxuryPacket = rand() % 2;
- for (int j = 0; j < tickets[i]; j++)
- if (theather->isFull()) {
- throw(TicketException("No enough space.", tickets[i]));
- }
- else {
- theather->buyTicket(isLuxuryPacket);
- }
- }
- }
- catch (TicketException& e)
- {
- cout << e.what() << e.getTicketNumber() << endl;
- }
- }
- int main() {
- int array[] = { 1,8,3,5,4,9,0,2,2,2 };
- cout << countRuns(array, 10) << endl;
- Song demo("In the end", 105);
- cout << demo << endl;
- Song* songs = getSong();
- cout << countRuns(songs, 10) << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment