-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4b3d1f4
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <iostream> | ||
#include<iostream> | ||
|
||
class Building | ||
{ | ||
public: | ||
Building() : id_(-1) {}; | ||
Building(int identifier); | ||
~Building(); | ||
void print(std::ostream& ou); | ||
Building& operator=(const Building& rhs); | ||
private: | ||
int id_; | ||
}; | ||
|
||
Building::Building(int identifier) : id_(identifier) { | ||
std::cout<< "Building::Building (" << identifier << ") at "<< this <<std::endl; | ||
} | ||
|
||
Building::~Building() { | ||
std::cout<< "~Building" << id_<<std::endl; | ||
} | ||
|
||
void Building::print(std::ostream& out){ | ||
out<<"Building "<<id_<<" at "<<this << std::endl; | ||
|
||
} | ||
Building& Building::operator=(const Building& rhs){ | ||
if(this != &rhs ) | ||
{ | ||
id_=rhs.id_; | ||
} | ||
std::cout<<"Copy Done"<<std::endl; | ||
return *this; | ||
} | ||
|
||
|
||
int main(int argc , char** argv) | ||
{ | ||
std::cout << "Welcome to SimTown ! Please enter the street size" << std::endl; | ||
int index{-99}; | ||
Building* street[10]; | ||
for (int i=0; i<10 ; ++i) | ||
{ | ||
street[i]=nullptr; | ||
} | ||
std::cin >> index; | ||
int counter{0}; | ||
while(index != -99 && counter< 10) | ||
{ | ||
street[counter]= new Building(index); | ||
std::cin >> index; | ||
counter++; | ||
} | ||
for (int i=0; i<10 ; ++i) | ||
{ | ||
if(street[i] != nullptr) | ||
{ | ||
street[i]->print(std::cout); | ||
} | ||
} | ||
for (int i=0; i<10 ; ++i) | ||
{ | ||
delete street[i]; | ||
} | ||
std::cout << "Done"<<std::endl; | ||
return 0; | ||
} |