From b1d88d8eaa496673db0ed7fefc4001accebb28b2 Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:30:22 +0800 Subject: [PATCH 01/16] Create Rectangle.h This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_11/Rectangle.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 201816040114/Ex09_11/Rectangle.h diff --git a/201816040114/Ex09_11/Rectangle.h b/201816040114/Ex09_11/Rectangle.h new file mode 100644 index 00000000..2bf05f6e --- /dev/null +++ b/201816040114/Ex09_11/Rectangle.h @@ -0,0 +1,22 @@ +#ifndef RECTANGLE_H_INCLUDED +#define RECTANGLE_H_INCLUDED + +class Rectangle +{ +public: + explicit Rectangle(double=1.0,double=1.0); + void setLength(double); + void setWidth(double); + double Perimeter(); + double Area(); + void Range(); +private: + double length; + double width; + double perimeter; + double area; +}; + + + +#endif // RECTANGLE_H_INCLUDED From da3a3b2e160ff078f8890ee4f5d61f214701a931 Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:33:09 +0800 Subject: [PATCH 02/16] Create Rectangle.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_11/Rectangle.cpp | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 201816040114/Ex09_11/Rectangle.cpp diff --git a/201816040114/Ex09_11/Rectangle.cpp b/201816040114/Ex09_11/Rectangle.cpp new file mode 100644 index 00000000..2472f83a --- /dev/null +++ b/201816040114/Ex09_11/Rectangle.cpp @@ -0,0 +1,46 @@ +#include "Rectangle.h" +#include +#include +using namespace std; + +Rectangle::Rectangle(double a,double b) +{ + setLength(a); + setWidth(b); +} + +void Rectangle::setLength(double a) +{ + length=a; +} + +void Rectangle::setWidth(double a) +{ + width=a; +} + +double Rectangle::Perimeter() +{ + perimeter=(length+width)*2; + return perimeter; +} + +double Rectangle::Area() +{ + area=length*width; + return area; +} + +void Rectangle::Range() +{ + if(length<=0.0||length>=20.0) + { + cout<<"The length over 20 or less than 0"<=20.0) + { + cout<<"The width over 20 or less than 0"< Date: Sun, 17 Nov 2019 14:33:48 +0800 Subject: [PATCH 03/16] Create Ex09_11.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_11/Ex09_11.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 201816040114/Ex09_11/Ex09_11.cpp diff --git a/201816040114/Ex09_11/Ex09_11.cpp b/201816040114/Ex09_11/Ex09_11.cpp new file mode 100644 index 00000000..04505f5f --- /dev/null +++ b/201816040114/Ex09_11/Ex09_11.cpp @@ -0,0 +1,12 @@ +#include +#include "Rectangle.h" + + +using namespace std; + +int main() +{ + Rectangle rectangle(10,5); + rectangle.Range(); + cout< Date: Sun, 17 Nov 2019 14:35:26 +0800 Subject: [PATCH 04/16] Create Ex09_12.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_12/Ex09_12.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 201816040114/Ex09_12/Ex09_12.cpp diff --git a/201816040114/Ex09_12/Ex09_12.cpp b/201816040114/Ex09_12/Ex09_12.cpp new file mode 100644 index 00000000..a797e3e3 --- /dev/null +++ b/201816040114/Ex09_12/Ex09_12.cpp @@ -0,0 +1,13 @@ +#include +#include "Point.h" +#include "Rectangle.h" + +using namespace std; + +int main() +{ + Point a(2,4),b(2,1),c(6,1),d(6,4); + Rectangle rectangle(a,b,c,d); + rectangle.square(); + cout< Date: Sun, 17 Nov 2019 14:37:01 +0800 Subject: [PATCH 05/16] Create Point.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_12/Point.cpp | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 201816040114/Ex09_12/Point.cpp diff --git a/201816040114/Ex09_12/Point.cpp b/201816040114/Ex09_12/Point.cpp new file mode 100644 index 00000000..c539df77 --- /dev/null +++ b/201816040114/Ex09_12/Point.cpp @@ -0,0 +1,43 @@ +#include "Point.h" +#include +using namespace std; + +Point::Point(double a,double b) +{ + setX(a); + setY(b); +} + +void Point::setX(double a) +{ + if(a>0&&a<20) + { + x=a; + } + else + { + throw invalid_argument("x must be 0-20"); + } +} + +void Point::setY(double a) +{ + if(a>0&&a<20) + { + y=a; + } + else + { + throw invalid_argument("y must be 0-20"); + } +} + +double Point::getX() +{ + return x; +} + +double Point::getY() +{ + return y; +} From 61366e7947986501bb11d9e412bb552397783daa Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:37:35 +0800 Subject: [PATCH 06/16] Create Point.h This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_12/Point.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 201816040114/Ex09_12/Point.h diff --git a/201816040114/Ex09_12/Point.h b/201816040114/Ex09_12/Point.h new file mode 100644 index 00000000..d27ae423 --- /dev/null +++ b/201816040114/Ex09_12/Point.h @@ -0,0 +1,20 @@ +#ifndef POINT_H_INCLUDED +#define POINT_H_INCLUDED +using namespace std; + +class Point +{ +public: + Point(double,double); + void setX(double); + void setY(double); + double getX(); + double getY(); +private: + double x; + double y; +}; + + + +#endif // POINT_H_INCLUDED From fed48c45fdfb8f7f9493702549aa2b81ef228982 Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:38:38 +0800 Subject: [PATCH 07/16] Create Rectangle.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_12/Rectangle.cpp | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 201816040114/Ex09_12/Rectangle.cpp diff --git a/201816040114/Ex09_12/Rectangle.cpp b/201816040114/Ex09_12/Rectangle.cpp new file mode 100644 index 00000000..ce77a959 --- /dev/null +++ b/201816040114/Ex09_12/Rectangle.cpp @@ -0,0 +1,38 @@ +using namespace std; +#include "Rectangle.h" +#include "Point.h" +#include + +Rectangle::Rectangle(Point &a,Point &b,Point &c,Point &d) +:A(a),B(b),C(c),D(d) +{ + +} + +void Rectangle::square() +{ + if(A.getY()-B.getY()>C.getX()-B.getX()) + { + length=A.getY()-B.getY(); + width=C.getX()-B.getX(); + } + if(A.getY()-B.getY() Date: Sun, 17 Nov 2019 14:39:09 +0800 Subject: [PATCH 08/16] Create Rectangle.h This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_12/Rectangle.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 201816040114/Ex09_12/Rectangle.h diff --git a/201816040114/Ex09_12/Rectangle.h b/201816040114/Ex09_12/Rectangle.h new file mode 100644 index 00000000..94cf2b0e --- /dev/null +++ b/201816040114/Ex09_12/Rectangle.h @@ -0,0 +1,22 @@ +#ifndef RECTANGLE_H_INCLUDED +#define RECTANGLE_H_INCLUDED +using namespace std; +#include "Point.h" +class Rectangle +{ +public: + Rectangle(Point &,Point &,Point &,Point &); + void square(); + double getPerimeter(); + double getArea(); +private: + Point A,B,C,D; + double length; + double width; + double perimeter; + double area; +}; + + + +#endif // RECTANGLE_H_INCLUDED From 5ffc1542e8af9e5af1c2a673f820fe776313d37b Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:47:19 +0800 Subject: [PATCH 09/16] Create Ex09_22.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_22/Ex09_22.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 201816040114/Ex09_22/Ex09_22.cpp diff --git a/201816040114/Ex09_22/Ex09_22.cpp b/201816040114/Ex09_22/Ex09_22.cpp new file mode 100644 index 00000000..67ff59fe --- /dev/null +++ b/201816040114/Ex09_22/Ex09_22.cpp @@ -0,0 +1,12 @@ +#include +#include "Time.h" + +using namespace std; + +int main() +{ + Time t1; + t1.printUniversal(); + cout< Date: Sun, 17 Nov 2019 14:47:57 +0800 Subject: [PATCH 10/16] Create Time.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_22/Time.cpp | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 201816040114/Ex09_22/Time.cpp diff --git a/201816040114/Ex09_22/Time.cpp b/201816040114/Ex09_22/Time.cpp new file mode 100644 index 00000000..f6eeba9b --- /dev/null +++ b/201816040114/Ex09_22/Time.cpp @@ -0,0 +1,43 @@ +#include "Time.h" +#include +#include +#include +using namespace std; +Time::Time(int hour,int minute,int second) +{ + setTime(hour,minute,second); +} + +void Time::setTime(int h,int m,int s) +{ + if(h>=0&&h<24&&m>=0&&m<60&&s>=0&&s<60) + second=h*60*60+m*60+s; + else + throw invalid_argument("hour,minute or second was out of range"); +} + +unsigned Time::getHour() const +{ + return (second-second%3600)/3600; +} + +unsigned Time::getMinute() const +{ + return (second-second%3600)/60; +} + +unsigned Time::getSecond() const +{ + return second%3600; +} + +void Time::printUniversal() const +{ + cout< Date: Sun, 17 Nov 2019 14:48:26 +0800 Subject: [PATCH 11/16] Create Time.h This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_22/Time.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 201816040114/Ex09_22/Time.h diff --git a/201816040114/Ex09_22/Time.h b/201816040114/Ex09_22/Time.h new file mode 100644 index 00000000..eab02184 --- /dev/null +++ b/201816040114/Ex09_22/Time.h @@ -0,0 +1,20 @@ +#ifndef TIME_H_INCLUDED +#define TIME_H_INCLUDED +using namespace std; +class Time +{ +public: + explicit Time(int=0,int=0,int=0); + void setTime(int,int,int); + unsigned int getHour()const; + unsigned int getMinute()const; + unsigned int getSecond()const; + void printUniversal()const; + void printStandard()const; +private: + unsigned int second; +}; + + + +#endif // TIME_H_INCLUDED From 214dbbe73b39ac9e83262ba5bc1dac4a1ab5c6df Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:49:17 +0800 Subject: [PATCH 12/16] Create Ex09_23.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_23/Ex09_23.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 201816040114/Ex09_23/Ex09_23.cpp diff --git a/201816040114/Ex09_23/Ex09_23.cpp b/201816040114/Ex09_23/Ex09_23.cpp new file mode 100644 index 00000000..eb6df0d9 --- /dev/null +++ b/201816040114/Ex09_23/Ex09_23.cpp @@ -0,0 +1,18 @@ +#include "Card.h" +#include "DeckOfCards.h" +#include + +using namespace std; + +int main() +{ + int i; + DeckofCards p; + p.shuffle(); + for (i=0;i<52;i++) + { + cout < Date: Sun, 17 Nov 2019 14:49:43 +0800 Subject: [PATCH 13/16] Create Card.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_23/Card.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 201816040114/Ex09_23/Card.cpp diff --git a/201816040114/Ex09_23/Card.cpp b/201816040114/Ex09_23/Card.cpp new file mode 100644 index 00000000..579f940d --- /dev/null +++ b/201816040114/Ex09_23/Card.cpp @@ -0,0 +1,12 @@ +#include "Card.h" +Card::Card(int a,int b) +{ + face=a; + suit=b; +} +string Card::toString() +{ + string card=" of "; + card=Face[face]+card+Suit[suit]; + return card; +} From bfbf8d0ed80879b6495a6afa0520a1007f0ebcc9 Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:50:08 +0800 Subject: [PATCH 14/16] Create Card.h This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_23/Card.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 201816040114/Ex09_23/Card.h diff --git a/201816040114/Ex09_23/Card.h b/201816040114/Ex09_23/Card.h new file mode 100644 index 00000000..0319baf8 --- /dev/null +++ b/201816040114/Ex09_23/Card.h @@ -0,0 +1,20 @@ +#ifndef CARD_H_INCLUDED +#define CARD_H_INCLUDED +using namespace std; +#include +class Card +{ +public: + explicit Card(int,int); + void setCard(int,int); + string toString(); +private: + int face; + int suit; + string Face[13]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; + string Suit[4] = {"Spade","Heart","Diamond","Club"}; +}; + + + +#endif // CARD_H_INCLUDED From b45f42e83c0565fa9f2488992b87d2badfb579e4 Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:50:41 +0800 Subject: [PATCH 15/16] Create DeckofCards.cpp This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_23/DeckofCards.cpp | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 201816040114/Ex09_23/DeckofCards.cpp diff --git a/201816040114/Ex09_23/DeckofCards.cpp b/201816040114/Ex09_23/DeckofCards.cpp new file mode 100644 index 00000000..f4f713e9 --- /dev/null +++ b/201816040114/Ex09_23/DeckofCards.cpp @@ -0,0 +1,50 @@ +#include "Card.h" +#include "DeckOfCards.h" +#include +#define random(x) (rand()%x) + +using namespace std; + +DeckofCards::DeckofCards() +{ + int i,j; + for (i=0;i<4;i++) + { + for(j=0;j<13;j++) + { + Card a(j,i); + deck.push_back(a); + } + } +} +bool DeckofCards::moreCards() +{ + if(currentCard>=52) + { + return false; + } + + + return true; + +} + +void DeckofCards::shuffle() +{ + int i,a; + Card temp(0,0); + srand((int)time(0)); + for(i=0;i<52;i++) + { + a=random(52); + Card temp=deck[i]; + deck[i]=deck[a]; + deck[a]=temp; + } +} + +Card DeckofCards::dealCard() +{ + currentCard=currentCard+1; + return deck[currentCard-1]; +} From ce674bbd0209b23c60f665fbdd24a7003d7268de Mon Sep 17 00:00:00 2001 From: XueLing-c <56784633+XueLing-c@users.noreply.github.com> Date: Sun, 17 Nov 2019 14:51:08 +0800 Subject: [PATCH 16/16] Create DeckofCards.h This is my assignment 04 Student ID:201816040114 --- 201816040114/Ex09_23/DeckofCards.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 201816040114/Ex09_23/DeckofCards.h diff --git a/201816040114/Ex09_23/DeckofCards.h b/201816040114/Ex09_23/DeckofCards.h new file mode 100644 index 00000000..94ca3f12 --- /dev/null +++ b/201816040114/Ex09_23/DeckofCards.h @@ -0,0 +1,21 @@ +#ifndef DECKOFCARDS_H_INCLUDED +#define DECKOFCARDS_H_INCLUDED +#include "Card.h" +#include +using std::vector; +class DeckofCards +{ + friend Card; +public: + DeckofCards(); + void shuffle(); + Card dealCard(); + bool moreCards(); +private: + int currentCard=1; + vector deck; +}; + + + +#endif // DECKOFCARDS_H_INCLUDED