Tuesday, December 9, 2014

C++ using Date and Textcomplex pro



Namespace Program

#include 
#include
#include 
using namespace std;
complex::complex(double real, double imag)
   : real(real), imag(imag) { }
double complex::getreal() const 
{
   return real;
}
void complex::setreal(double real) 
{
   this->real = real;
}
double complex::getImag() const 
{
   return imag;
}
void complex::setimag(double imag) 
{
   this->imag = imag;
}
void complex::setvalue(double real, double imag) 
{
   this->real = real;
   this->imag = imag;
}
void complex::print() const 
{
   cout << '(' << real << ',' << imag << ')' << endl;
}
bool complex::isreal() const 
{
   return (imag == 0);
}
bool complex::isimaginary() const 
{
   return (real == 0);
}
complex & complex::addinto(const complex & another) 
 {
   real += another.real;
   imag += another.imag;
   return *this;
}
complex & complex::addinto(double real, double imag) 
{
   this->real += real;
   this->imag += imag;
   return *this;
}
complex complex::addreturnnew(const complex & another) const 
{       
   return complex(real + another.real, imag + another.imag);
}
complex complex::addreturnnew(double real, double imag) const 
{
   return complex(this->real + real, this->imag + imag);
}
Test Complex

#include 
#include 
#include 
using namespace std;
int main() 
{
   complex c1, c2(4, 5);
   c1.print();  
   c2.print();  
   c1.setvalue(6, 7);
   c1.print();  
   c1.setreal(0);
   c1.setimag(8);
   c1.print();  
   cout << boolalpha;  
   cout << "Is real? " << c1.isReal() << endl;           
   cout << "Is Imaginary? " << c1.isImaginary() << endl; 
   c1.addinto(c2).addinto(1, 1).print();  
   c1.print();  
   c1.addreturnnew(c2).print();   
   c1.print();  
   c1.addreturnnew(1, 1).print(); 
   c1.print();  
}
Date
 
#include
#include
#ifndef date_h
#define date_h
#include 
using namespace std;
class date 
{
private:
   int year;    
   int month;   
   int day;     
   const static string str_months[];
   const static string str_days[];
   const static int days_in_months[];
   const static int year_min = 1753;
   const static int year_max = 9999;
public:
   static bool isleapyear(int y);
   static bool isvaliddate(int y, int m, int d);
   static int getdayofweek(int y, int m, int d);
   date(int y, int m, int d);
   void setdate(int y, int m, int d);
   int getyear() const;
   int getmonth() const;
   int getday() const;
   void setyear(int y);
   void setmonth(int m);
   void setday(int d);
   void print() const;
   date & nextday();
   date & previousday();
   date & nextmonth();
   date & previousmonth();
   date & nextyear();
   date & previousyear();
};

No comments:

Post a Comment