Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment_04 #104

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions 201816040319/Ex09_11/Ex09_11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include <stdexcept>

#include "Rectangle.h"

using namespace std;

int main()
{

Rectangle r;
double Length;
double Width;

cout <<"please enter Length"<<endl;
cin >>Length;
cout <<"please enter width"<<endl;
cin >>Width;

r.setRectangle(Length,Width);

cout <<"Check the data"<<Length<<" "<<Width<<endl;

cout <<"The output value of perimeter:"<<r.perimenter()<<endl;
cout <<"The output value of area: "<<" "<<r.area()<<endl;


return 0;


}
33 changes: 33 additions & 0 deletions 201816040319/Ex09_11/Rectangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include "Rectangle.h"
#include <stdexcept>
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;
11 changes: 11 additions & 0 deletions 201816040319/Ex09_11/Rectangle.h
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions 201816040319/Ex09_12/Ex09_12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#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 :"<<width<<endl;
cout<<"this length is :"<<length<<endl;
cout<<"this perimeter is :"<<perimeter<<endl;
cout<<"this area is :"<<area<<endl;
r.setCharacter('*');
r.setPerimeterCharacter('#');
r.draw();
return 0;
}
106 changes: 106 additions & 0 deletions 201816040319/Ex09_12/Rectangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

#include<iostream>
#include"Rectangle.h"
#include<string.h>
#include<fstream>
#include<iomanip>
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<<outnumber<<" ";
}
cout<<endl;
}

else if(i==w-1)
{

for(i=w-1;i<w+Width-1;i++)
{
cout<<outnumber<<setw((l)*2);
if(i==w-1||i==w+Width-2)
{
for(k=0;k<Length;k++)
{
if(k==Length-1)
cout<<innumber;
else
cout<<innumber<<" ";
}

}
else
{
cout<<innumber<<setw((Length-1)*2)<<innumber;

}
cout<<setw((l)*2)<<outnumber<<endl;
}


}
else
{

cout<<outnumber<<setw(48)<<outnumber<<endl;
}
}


}
void Rectangle::setCharacter(char out)
{

outnumber=out;
}
void Rectangle::setPerimeterCharacter(char in)
{
innumber=in;
}

double Rectangle::getlength()
{
return Length;
}
double Rectangle::getwidth()
{
return Width;
}




29 changes: 29 additions & 0 deletions 201816040319/Ex09_12/Rectangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<iostream>
#include<string>


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;

};




29 changes: 29 additions & 0 deletions 201816040319/Ex09_22/Ex09_22.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include"Time.h"
using namespace std;

int main()
{
Time t1;
t1.setTime(10,49,59);
t1.printStandard();
cout<<endl;
t1.printUniversal();
cout<<endl;
t1.timetick();
t1.printStandard();
cout<<endl;
t1.printUniversal();
cout<<endl;
cout<<"timechange:";
t1.timechange();
t1.printTime();
cout<<"Standardtime:";
t1.timein(28923);
t1.printStandard();
cout<<endl;
cout<<"Universal:";
t1.printUniversal();
cout<<endl;
return 0;
}
116 changes: 116 additions & 0 deletions 201816040319/Ex09_22/Time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include<iostream>
#include<iomanip>
#include<stdexcept>
#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 :"<<endl;
cout<<data1<<endl;
cout<<"The localtime is :"<<endl;
cout<<data2<<endl;

}

void Time::setHour(int h)
{
if(h>=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<<setfill('0')<<setw(2)<<getHour()<<":"
<<setw(2)<<getMinute()<<":"<<setw(2)<<getSecond();
}
void Time::printStandard() const
{
cout<<((getHour()==0||getHour()==12)?12:getHour()%12)
<<":"<<setfill('0')<<setw(2)<<getMinute()
<<":"<<setw(2)<<getSecond()<<(hour<12?"AM":"PM");
}


Loading