diff --git a/201816040319/Ex09_11/Ex09_11.cpp b/201816040319/Ex09_11/Ex09_11.cpp new file mode 100644 index 00000000..c992e054 --- /dev/null +++ b/201816040319/Ex09_11/Ex09_11.cpp @@ -0,0 +1,31 @@ +#include +#include + +#include "Rectangle.h" + +using namespace std; + +int main() +{ + + Rectangle r; + double Length; + double Width; + + cout <<"please enter Length"<>Length; + cout <<"please enter width"<>Width; + + r.setRectangle(Length,Width); + + cout <<"Check the data"< +#include "Rectangle.h" +#include +using namespace std; + +Rectangle::Rectangle() + :length(0.0),width(0.0) + { + + } +void Rectangle::setRectangle(double Length,double Width) +{ + if((Length<20.0&&Length>0.0)&&(Width>0.0&&Width<20.0)) + { + length=Length; + width=Width; + } + /* else + thow invalide_argument( + "length,OR width was out of range"); + +*/}//end function rectangle + +double Rectangle::perimenter() +{ + return (2*length+2*width); +}//end function perimenter; + +double Rectangle::area() +{ + return length*width; +} +//end function area; diff --git a/201816040319/Ex09_11/Rectangle.h b/201816040319/Ex09_11/Rectangle.h new file mode 100644 index 00000000..58c1da6f --- /dev/null +++ b/201816040319/Ex09_11/Rectangle.h @@ -0,0 +1,11 @@ +class Rectangle +{ +public: + Rectangle(); + void setRectangle(double,double); + double perimenter(); + double area(); +private: + double length;//Define the length variable + double width; //Define the width variable +};//The end of class diff --git a/201816040319/Ex09_12/Ex09_12.cpp b/201816040319/Ex09_12/Ex09_12.cpp new file mode 100644 index 00000000..7fc74f0e --- /dev/null +++ b/201816040319/Ex09_12/Ex09_12.cpp @@ -0,0 +1,21 @@ +#include +#include"Rectangle.h" +using namespace std; + +int main() +{ + Rectangle r(5.0,2.0); + int perimeter,area,width,length; + width = r.getwidth(); + length = r.getlength(); + perimeter=r.perimeter(); + area = r.area(); + cout<<"this width is :"< +#include"Rectangle.h" +#include +#include +#include +using namespace std; +Rectangle::Rectangle(double length,double width) +{ + setlength(length); + setwidth(width); +} +double Rectangle::perimeter() +{ + int perimeter; + perimeter = 2*Length+2*Width; + return perimeter; +} +double Rectangle::area() +{ + int area; + area = Length*Width; + return area; +} +void Rectangle::setlength(double length) +{ + Length = length; +} +void Rectangle::setwidth(double width) +{ + Width = width; +} +void Rectangle::draw() +{ + + double l=(25-Length)/2; + double w=(25-Width)/2; + int i,k; + for( i = 0;i<25;i++) + { + if(i==0||i==24) + { for(int j =0; j <25;j++) + { + cout< +#include + + +class Rectangle +{ + +public: + Rectangle(double ,double ); + double perimeter(); + double area(); + void setlength(double ); + void setwidth(double ); + void draw(); + void setCharacter(char out); + void setPerimeterCharacter(char in); + double getlength(); + double getwidth(); +private: + double Length; + double Width; + char outnumber; + char innumber; + +}; + + + + diff --git a/201816040319/Ex09_22/Ex09_22.cpp b/201816040319/Ex09_22/Ex09_22.cpp new file mode 100644 index 00000000..03599fba --- /dev/null +++ b/201816040319/Ex09_22/Ex09_22.cpp @@ -0,0 +1,29 @@ +#include +#include"Time.h" +using namespace std; + +int main() +{ + Time t1; + t1.setTime(10,49,59); + t1.printStandard(); + cout< +#include +#include +#include"Time.h" +using namespace std; + +Time::Time(int hour,int minute,int second) +{ + setTime(hour,minute,second); +} +void Time::setTime(int h,int m,int s) +{ + setHour(h); + setMinute(m); + setSecond(s); +} +void Time::timechange() +{ + time(&data1); + localtime(&data2); +} +void Time::printTime() +{ + cout<<"The time is :"<=0&&h<24) + { + hour=h; + } + else + throw invalid_argument("minute must be in the range of 0-23"); + +} +void Time::setMinute(int m ) +{ + if(m>=0&&m<60) + { + minute=m; + } + else + throw invalid_argument("minute must be in the range of 0-59"); + +} +void Time::setSecond(int s ) +{ + if(s>=0&&s<60) + { + second=s; + } + else + throw invalid_argument("minute must be in the range of 0-59"); + +} +void Time::timetick() +{ + second++; + if(second==60) + { + minute++; + second=0; + } + if(minute==60) + { + hour++; + minute=0; + } + if(hour==24) + { + hour=0; + } +} +void Time::timein(int all) +{ + int h,m,s; + int a; + h=all/3600; + a=all%3600; + m=a/60; + a=a%60; + s=a; + setHour(h); + setMinute(m); + setSecond(s); +} + int Time::getHour() const +{ + return hour; +} + int Time::getMinute() const +{ + return minute; +} +int Time::getSecond() const +{ + return second; +} +void Time::printUniversal() const +{ + cout< +class Time +{ +public: + explicit Time(int=0 ,int=0 ,int=0); + void timechange(); + void printTime(); + void setTime(int ,int ,int ); + void setHour(int ); + void setMinute(int ); + void setSecond(int ); + void timetick(); + void timein(int ); + int getHour() const; + int getMinute() const; + int getSecond() const; + + void printUniversal() const; + void printStandard() const; +private: + int hour; + int minute; + int second; + int alltime; + time_t data1; + time_t data2; + +}; + + diff --git a/201816040319/Ex09_23/Card.cpp b/201816040319/Ex09_23/Card.cpp new file mode 100644 index 00000000..491b9daf --- /dev/null +++ b/201816040319/Ex09_23/Card.cpp @@ -0,0 +1,29 @@ +#include +#include"card.h" +#include + +Card::Card(int Face,int Suit) +{ + face = Face; + suit = Suit; +} +string Card::toString() +{ + return facedata[face]+" of "+suitdata[suit]; +} +int Card::getface() +{ + return face; +} +int Card::getsuit() +{ + return suit; +} + +const string Card::facedata[facenumber]= +{"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; + +const string Card::suitdata[suitnumber]= +{"heart","diamond","club","spade"}; + + diff --git a/201816040319/Ex09_23/Card.h b/201816040319/Ex09_23/Card.h new file mode 100644 index 00000000..a83bc238 --- /dev/null +++ b/201816040319/Ex09_23/Card.h @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +class Card +{ +public: + static const int facenumber = 13; + static const int suitnumber = 4; + Card(int ,int ); + int getface(); + int getsuit(); + string toString(); +private: + int face; + int suit; + static const string facedata[facenumber]; + static const string suitdata[suitnumber]; + + +}; + + + diff --git a/201816040319/Ex09_23/DeckOfCards.h b/201816040319/Ex09_23/DeckOfCards.h new file mode 100644 index 00000000..8a8f42e8 --- /dev/null +++ b/201816040319/Ex09_23/DeckOfCards.h @@ -0,0 +1,21 @@ +#include +#include +#include"Card.h" + +using namespace std; + +class DeckOfCards +{ +public: + DeckOfCards(); + void shuffle(); + Card dealcard(int ); + void beforecard(int ); + bool morecard(); + void judge(int ); +private: + vector deck; + int currentCard; +}; + + diff --git a/201816040319/Ex09_23/Ex09_23.cpp b/201816040319/Ex09_23/Ex09_23.cpp new file mode 100644 index 00000000..09b6e288 --- /dev/null +++ b/201816040319/Ex09_23/Ex09_23.cpp @@ -0,0 +1,20 @@ +#include +#include"DeckOfCards.h" +#include"card.h" + +using namespace std; + +int main() +{ + DeckOfCards card1; + card1.shuffle(); + card1.beforecard(10); + cout< +#include +#include"DeckOfCards.h" +#include"card.h" +#include +#include +#include + +DeckOfCards::DeckOfCards() +{ + + for (int j =0;j<52;j++) + { + Card card(j%13,j/13); + deck.push_back(card); + } + +} + +void DeckOfCards::shuffle() +{ + srand(time(0)); + int swap1[52]; + for (int j=0;j<52;j++) + { + swap1[j] = int (rand())%52; + } + + for (int i=0;i<52;i++) + { + Card change(0,0); + change = deck[i]; + deck[i] = deck[swap1[i]]; + deck[swap1[i]] = change + } +} +//返回下一张牌 +Card DeckOfCards::dealcard(int currentCard) +{ + cout<52||num<0) + { + cout<<"Enter a correct number!"; + } + else + { + for (int i = 0;i