Skip to content

Commit

Permalink
fmk - adding day 3
Browse files Browse the repository at this point in the history
  • Loading branch information
fmckenna committed Jun 7, 2023
1 parent 8a79b15 commit d194b40
Show file tree
Hide file tree
Showing 19 changed files with 2,538 additions and 0 deletions.
2,000 changes: 2,000 additions & 0 deletions assignments/C-Day3/ex1/big.txt

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions assignments/C-Day3/ex1/small.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0, 0.153779, 0.560532
1, 0.865013, 0.276724
2, 0.895919, 0.704462
3, 0.886472, 0.929641
4, 0.469290, 0.350208
5, 0.941637, 0.096535
6, 0.457211, 0.346164
7, 0.970019, 0.114938
8, 0.769819, 0.341565
9, 0.684224, 0.748597
19 changes: 19 additions & 0 deletions assignments/C-Day3/ex2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required (VERSION 2.6)
set (CMAKE_C_STANDARD 99)

project (Shapes)

include_directories(${PROJECT_SOURCE_DIR})
add_library(ShapeLib ColoredShape.cpp Rectangle.cpp Circle.cpp Ellipse.cpp)

add_executable(ex1 main1.cpp)
target_link_libraries (ex1 ShapeLib)

add_executable(ex2 main2.cpp)
target_link_libraries (ex2 ShapeLib)

add_executable(ex3 main3.cpp)
target_link_libraries (ex3 ShapeLib)

add_executable(ex4 main4.cpp)
target_link_libraries (ex4 ShapeLib)
22 changes: 22 additions & 0 deletions assignments/C-Day3/ex2/Circle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "Circle.h"

Circle::~Circle() {
std::cout << "Circle Destructor\n";
}

Circle::Circle(double radius, string color)
:ColoredShape(color)
{
r = radius;
}

double
Circle::getArea(void) {
return r*r*getPI();
}

double
Circle::getPI(void) {
return 3.14159;
}

21 changes: 21 additions & 0 deletions assignments/C-Day3/ex2/Circle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _CIRCLE
#define _CIRCLE

#include "ColoredShape.h"

class Circle: public ColoredShape {
public:
Circle(double r, string color);
~Circle();
double getArea(void);

protected:

private:
double r;
double getPI(void);
};

#endif // _CIRCLE


23 changes: 23 additions & 0 deletions assignments/C-Day3/ex2/ColoredShape.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "ColoredShape.h"

ColoredShape::ColoredShape(string col)
: color(col)
{

}

ColoredShape::~ColoredShape() {
std::cout << "ColoredShape Destructor\n";
}

const string &
ColoredShape::getColor() {
return color;
}

void
ColoredShape::printArea(std::ostream &s) {
s << "Color: " << color << " UNKOWN area: " << this->getArea() << "\n";
}


23 changes: 23 additions & 0 deletions assignments/C-Day3/ex2/ColoredShape.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef _COLORED_SHAPE
#define _COLORED_SHAPE

#include <iostream>
#include <string>
using std::string;

class ColoredShape {
public:
ColoredShape(string color);
virtual ~ColoredShape();

const string &getColor();
virtual double getArea(void) =0;
virtual void printArea(std::ostream &s);

private:
string color;
};

#endif // _COLORED_SHAPE


28 changes: 28 additions & 0 deletions assignments/C-Day3/ex2/Ellipse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "Ellipse.h"

Ellipse::~Ellipse() {
std::cout << "Ellipse Destructor\n";
}

Ellipse::Ellipse(double a, double b, string color)
:ColoredShape(color)
{
ax1 = a;
ax2 = b;
}

double
Ellipse::getArea(void) {
return ax1*ax2*getPI();
}

double
Ellipse::getPI(void) {
return 3.14159;
}

void
Ellipse::printArea(std::ostream &s) {
s << "Ellipse: color: " << this->getColor() << ", area: " << this->getArea() << "\n";
}

23 changes: 23 additions & 0 deletions assignments/C-Day3/ex2/Ellipse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef _ELLIPSE_H
#define _ELLIPSE_H

#include "ColoredShape.h"

class Ellipse: public ColoredShape {
public:
Ellipse(double a, double b, string color);
~Ellipse();
double getArea(void);
void printArea(std::ostream &s);

protected:

private:
double ax1;
double ax2;
double getPI(void);
};

#endif // _ELLIPSE_H


26 changes: 26 additions & 0 deletions assignments/C-Day3/ex2/Rectangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "Rectangle.h"

int Rectangle::numRect = 0;

Rectangle::~Rectangle() {
numRect--;
std::cout << "Rectangle Destructor " << this->getColor() << "\n";
}

Rectangle::Rectangle(double w, double d, string color)
:ColoredShape(color), width(w), height(d)
{
numRect++;
}

double
Rectangle::getArea(void) {
return width*height;
}

void
Rectangle::printArea(std::ostream &s) {
s << "Rectangle: color: " << this->getColor() << ", area: "
<< width * height << " numRect: " << numRect << "\n";
}

22 changes: 22 additions & 0 deletions assignments/C-Day3/ex2/Rectangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _RECTANGLE
#define _RECTANGLE

#include "ColoredShape.h"

class Rectangle: public ColoredShape {
public:
Rectangle(double w, double h, string color);
~Rectangle();
double getArea(void);
void printArea(std::ostream &s);

protected:

private:
double width, height;
static int numRect;
};

#endif // _RECTANGLE


20 changes: 20 additions & 0 deletions assignments/C-Day3/ex2/main1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Rectangle.h"
#include "Ellipse.h"

int main(int argc, char **argv) {
Rectangle s1(1.0, 2.0, "red");
ColoredShape *s2 = new Rectangle(3.0, 1.0, "blue");
ColoredShape *s3 = new Ellipse(3.0,2.0,"purple");
// Shape *s4 = new Square(3.0, "pink");

s1.printArea(std::cout);
s2->printArea(std::cout);
s3->printArea(std::cout);
// s4->printArea(std::cout);

delete s2;
delete s3;
return 0;
}


18 changes: 18 additions & 0 deletions assignments/C-Day3/ex2/main2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Rectangle.h"
#include "Circle.h"

int main(int argc, char **argv) {
Circle s1(2.0, "red");
ColoredShape *s2 = new Rectangle(1.0, 2.0, "blue");
ColoredShape *s3 = new Rectangle(3.0,2.0, "green");

s1.printArea(std::cout);
s2->printArea(std::cout);
s3->printArea(std::cout);

delete s2;
delete s3;
return 0;
}


27 changes: 27 additions & 0 deletions assignments/C-Day3/ex2/main3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "Rectangle.h"
#include "Circle.h"

#include <list>

int main(int argc, char **argv) {
Circle s1(2.0, "red");
ColoredShape *s2 = new Rectangle(1.0, 2.0, "blue");
ColoredShape *s3 = new Rectangle(3.0,2.0, "green");

std::list<ColoredShape*> theShapes;

theShapes.push_front(&s1);
theShapes.push_front(s2);
theShapes.push_front(s3);

std::list<ColoredShape *>::iterator it;
for (it = theShapes.begin(); it != theShapes.end(); it++) {
(*it)->printArea(std::cout);
}

delete s2;
delete s3;
return 0;
}


37 changes: 37 additions & 0 deletions assignments/C-Day3/ex2/main4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "Rectangle.h"
#include "Circle.h"
#include "Ellipse.h"

#include <list>
#include <vector>

typedef std::list<ColoredShape*> Container;
//typedef std::vector<ColoredShape*> Container;

typedef Container::iterator Iter;

int main(int argc, char **argv) {
Container theShapes;

Circle s1(2.0, "red");
ColoredShape *s2 = new Rectangle(1.0, 2.0, "blue");
ColoredShape *s3 = new Rectangle(3.0,2.0, "green");
ColoredShape *s4 = new Ellipse(3.0,2.0, "purple");

theShapes.push_front(&s1);
theShapes.push_front(s2);
theShapes.push_front(s3);
theShapes.push_front(s4);

Iter it;
for (it = theShapes.begin(); it != theShapes.end(); it++) {
(*it)->printArea(std::cout);
}

delete s2;
delete s3;
delete s4;
return 0;
}


9 changes: 9 additions & 0 deletions assignments/C-Day3/ex3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required (VERSION 2.6)
set (CMAKE_C_STANDARD 99)

project (Shapes)

include_directories(${PROJECT_SOURCE_DIR})

add_executable(ex1 main.cpp Vector.cpp)

Loading

0 comments on commit d194b40

Please sign in to comment.