using namespace std;
class A{
int a,b;
public:
A(int m,int n){a=m;b=n;}//带参数构造函数
void show();
};
void A::show()
{
cout<<a<<","<<b<<endl;
}
int main(int argc, char **argv)
{
A aa(3,4);
aa.show();
return 0;
}
*图书馆书籍信息
*************************************************/
#include <iostream>
using namespace std;
const int IN=1;
const int CHECKED_OUT=0;
class Book{
char author[60];//作者
char title[60];//书名
int status;//借出状态
public:
Book(char *n,char *t,int s);//构造函数
int getStatus(){return status;}
void setStatus(int s){status=s;}
void show();
};
Book::Book(char *n,char *t,int s)
{
strcpy(author,n);
strcpy(title,t);
status=s;
}
void Book::show()
{
cout<<"<<"<<title<<">>"<<endl;
cout<<"作者:"<<author<<endl;
if(status==IN)cout<<"在馆内"<<endl;
else
cout<<"已借出"<<endl;
}
int main(int argc, char **argv)
{
Book b1("猴子与老猪","张三",IN);
b1.show();
return 0;
}
#include <iostream>
using namespace std;
class A{
int a;
public:
A(int j){a=j;}
void show();
};
void A::show()
{
cout<<a<<endl;
}
int main(int argc,char**argv)
{
A aa=123;//注意这里的初始化
aa.show();
return 0;
}