Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1498146
  • 博文数量: 329
  • 博客积分: 2773
  • 博客等级: 少校
  • 技术积分: 4219
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:17
个人简介

淡定从容,宁静致远

文章分类

全部博文(329)

文章存档

2016年(4)

2015年(50)

2014年(68)

2013年(45)

2012年(162)

分类: C/C++

2012-12-18 22:02:45

#include
using namespace std;
typedef struct stu
{
 int id;
 string name;
 int math;
}student;
int main()
{
 student stu1;
 stu1.id=1;
 stu1.name="张三";
 stu1.math=-20;
 cout<<"姓名:"<
 cout<<"成绩:"< return 0;
}
***************************************************************************************
#include
using namespace std;
void add(int x,int y)
{
 int z;
 z=x+y;
 cout<<"x+y="<}
void add(double x,double y)
{
 double z;
 z=x+y;
 cout<<"x+y="<
}
void add(int x,int y,int z)
{

}
void add(string x,string y)
{
 string z;
 z=x+y;
 cout<<"x+y="<}
void add(int x,double y)
{
 double z;
 z=(double)x+y;
 cout<<"x+y="<}
void add(double x,int  y)
{
 double z;
 z=x+(double)y;
 cout<<"x+y="<}
class A
{
    void add()
 {
 
 }
 void add(int x,int y)
 {
 
 }
};
int main()
{
 add(15,25);
 add(10.23,8.389);
 add("anc","def");
 add(10.5,56);
 return 0;
}
 

***********************************************************************************
#include
using namespace std;
void print(int x=100,int
  y=200,int z=500)
{
 cout<<"x="<
 cout<<"y="<
 cout<<"z="<
}
int main()
{
 print();
 return 0;
}
**********************************************************************************
#include
using namespace std;
class A
{
 private:
  const int x;
  const int y;
  int m;
  int &rm;
  int z;
 public:
  A(int x1,int y1,int
    z1):x(x1),y(y1),rm(m),z(z1)
  {
  
  }
  void print()
  {
   cout<<"x="<  
   cout<<"y="<   cout<<"z="<  }
};
int main()
{
 A a(10,20,30);
 a.print();
 A a1(50,60,70);
 a1.print();

 return 0;
}
***********************************************************************
#include
using namespace std;
class A
{
 public:
  mutable int x;
  int y;
  int z;
 public:
  A()
  {
   cout<<"无参构造函数"<  }
  A(int x1,int y1,int z1)
  {
   x=x1;
   y=y1;
   z=z1;
  
   cout<<"有参构造函数"<  }
  void set(int x1)const
  {
   x=x1;
   
   
  
  }
  void print()const
  {
   cout<<"x="<   cout<<"y="<   cout<<"z="<   cout<<"const函数"<    
  }
  void print()
  {
  
   cout<<"x="<   cout<<"y="<   cout<<"z="<   cout<<"非const函数"<  }
};
int main()
{
 const A a(100,200,300);
 a.x=800;
 a.set(1000);
 //a.set(700,800,900);
 a.print();
 A a1(1000,2000,3000);
 a1.print();
 return 0;
}
 
 
********************************************************************
#include
using namespace std;
class A
{
 public:
  static int x;
  int y;
  int z;
  void print()
  {
   cout<   printstatic(); 
  }
  static void printstatic()
  {
   cout<  
  }
};
int A::x=0;
int main()
{
 A a;
 A a1;
 a.x=100;
 cout<<"a1.x="< a1.x=200;
 cout<<"a.x="< cout<<"&a.x="<<&a.x<
 cout<<"&a1.x="<<&a1.x< cout<<"A::x="<
 cout<<"&A::x="<<&A::x< A::printstatic();
 return 0;
}
 
**********************************************************************
#include
using namespace std;
class student
{
 public:
  int id;
  string name;
  int math;
 public:
  student()
  {
   id=0;
   math=0;
   name="";
   cout<<"无参构造函数"<  
  }
  student(int id1,string
    name1,int
    math1)
  {
   id=id1;
   name=name1;
   if(math1>=0)
   {
   
    math=math1;
   }
   else
   {
       math=0;
    cout<<"数据错误"<   }
   cout<  }
  void set(int id1,string name1,int
    math1)
  {
   id=id1;
   name=name1;
   if(math1>=0)
   {
   
    math=math1;
   }
   else
   {
    math=0;
    cout<<"数据输入错误,请重新输入"<   }
  
  }
   void print()
  {
  
   cout<<"this="<   cout<<"id:"<   
   cout<<"姓名:"<   cout<<"成绩:"<  
  }
  ~student()
  {
  
   cout<  }

};
int main()
{
// student *p=new student;
// p->set(1,"aa",100);
// p->print();
// delete p;
 student *p1=new student[3];
 p1[0].set(1,"aa",100);
 p1[1].set(2,"bb",60);
 p1[0].print();
 p1[1].print();
 delete []p1;
// p->set(1,"aa",100);
// p->print();
// delete p;
/* student *p;
 student stu1;
 p=&stu1;
 p->id=1;
 p->name="李呈";
 p->math=100;
 p->print();
 student &rstu1=stu1;
 rstu1.id=2;
 rstu1.print();
*/
// student stu1(1,"张三",100);
// student stu2(2,"aa",60);
// stu1.id=1;
// stu1.name="张三";
// student stu3(3,"李四",80); 
// stu2.id=2;
// stu2.name="李四";
// stu1.print();
// stu2.print();

// cout<<"&stu1="<<&stu1</* cout<<"&stu1.id="<<&stu1.idi< cout<<"&stu1.name="<<&stu1.name<
 cout<<"&stu1.math="<<&stu1.math<*/
// cout<<"&stu2="<<&stu2</* cout<<"&stu2.id="<<&stu2.id< cout<<"&stu2.name="<<&stu2.name<
 cout<<"&stu2.math="<<&stu2.math< return 0;
}
 
阅读(1363) | 评论(0) | 转发(1) |
0

上一篇:继承

下一篇:函数模板

给主人留下些什么吧!~~