Skip to content

Commit

Permalink
20/09
Browse files Browse the repository at this point in the history
  • Loading branch information
BenPinet committed Sep 21, 2023
0 parents commit 4b3d1f4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
Binary file added SimTown.exe
Binary file not shown.
Binary file added a.out
Binary file not shown.
Empty file added building.h
Empty file.
68 changes: 68 additions & 0 deletions main.cpp
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;
}

0 comments on commit 4b3d1f4

Please sign in to comment.