Skip to content

Instantly share code, notes, and snippets.

@Fusion86
Last active April 16, 2019 17:59
Show Gist options
  • Save Fusion86/87be8b374fa8acef9f09195672864252 to your computer and use it in GitHub Desktop.
Save Fusion86/87be8b374fa8acef9f09195672864252 to your computer and use it in GitHub Desktop.
#include "book.h"
#include <iostream>
void book::print()
{
print_title();
print_author();
print_text();
}
void book::print_text()
{
std::cout << text << "\n";
}
void book::print_title()
{
std::cout << title << "\n";
}
void book::print_author()
{
std::cout << author << "\n";
}
#pragma once
#include <string>
class book
{
private:
std::string text;
std::string author;
std::string title;
void print_text();
void print_author();
void print_title();
public:
book(
const std::string &text,
const std::string &author,
const std::string &title)
: text(text),
author(author),
title(title)
{
}
void print();
};
#include "furniture.h"
#include <iostream>
Stool::Stool(int n_legs, int n_seats)
{
this->n_legs = n_legs;
this->n_seats = n_seats;
}
void Stool::print()
{
std::cout << "This stool has " << n_legs << " legs and " << n_seats << " seats" << std::endl;
}
void Stool::removeLeg()
{
n_legs--; // Er staat nergens dat we ervoor moeten zorgen dat dit een positief getal blijft
}
Table::Table(int n_legs, int length, int width)
{
this->n_legs = n_legs;
this->length = length;
this->width = width;
}
void Table::print()
{
std::cout << "This table has " << n_legs << " legs, is " << length << "m long and " << width << "m wide" << std::endl;
}
void Table::addLegs(int count)
{
n_legs += 4;
}
Furniture::Furniture(Stool stool1, Stool stool2, Stool stool3, Stool stool4, Table table) : stool1(stool1), stool2(stool2), stool3(stool3), stool4(stool4), table(table)
{
}
void Furniture::print()
{
stool1.print();
stool2.print();
stool3.print();
stool4.print();
table.print();
}
void Furniture::makeMoreHipster()
{
stool1.removeLeg();
stool2.removeLeg();
stool3.removeLeg();
stool4.removeLeg();
table.addLegs(4);
}
#pragma once
class Stool
{
private:
int n_legs;
int n_seats;
public:
Stool(int n_legs, int n_seats);
void print();
void removeLeg();
};
class Table
{
private:
int n_legs;
int length;
int width;
public:
Table(int n_legs, int length, int width);
void print();
void addLegs(int count);
};
class Furniture
{
private:
Stool stool1;
Stool stool2;
Stool stool3;
Stool stool4;
Table table;
public:
Furniture(Stool stool1, Stool stool2, Stool stool3, Stool stool4, Table table);
void makeMoreHipster();
void print();
};
#include <iostream>
#include "book.h"
#include "furniture.h"
int main()
{
book b("(this page is intentionally left blank)", "Frans Willem", "JavaScript: The Good Parts");
b.print();
Stool stool1(4, 1);
Stool stool2(4, 1);
Stool stool3(6, 1);
Stool stool4(6, 1);
Table table(4, 4, 3);
Furniture furniture(stool1, stool2, stool3, stool4, table);
std::cout << "Normal furniture" << std::endl;
furniture.print();
std::cout << "Hipster furniture" << std::endl;
furniture.makeMoreHipster();
furniture.print();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment