c++ 类 helloworld

a.h

#ifndef A_H_
#define A_H_
#include
<iostream>

class Tdate{
public:
void Set(int,int,int);
int IsLeapYear();
void Print();
private:
int month;
int day;
int year;
};

#endif

  

a.cc

#include <iostream>      
#include
"a.h"
using namespace std;

void Tdate::Set(int m,int d,int y)
{
month
=m; day=d; year=y;
}

int Tdate::IsLeapYear()
{
return (year%4==0&&year%100!=0)||(year%400==0);
}

void Tdate::Print()
{
cout
<<month <<"/" <<day <<"/" <<year <<endl;
}

  

main.cc

#include        <cstdlib>
#include
<fstream>
#include
<iomanip>
#include
<iostream>
#include
"a.h"

using namespace std;

int
main (
int argc, char *argv[] )
{
Tdate s;
s.Set(
2,15,1988);
s.Print();
cout
<< "\nProgram " << argv[0] << endl << endl;

return EXIT_SUCCESS;
}
// ---------- end of function main ----------

  

编译:Makefile

all:main                                                                                                                                                                         
main:main.cc a.cc
g
++ -g -Wall -O0 main.cc a.cc -o main

  

*********output*******
2/15/1988

Program .
/main

  

posted @ 2011-07-21 10:44  wangkangluo1  阅读(731)  评论(0编辑  收藏  举报