C++零基础代码

#include
using namespace std;
#include
#define NAME “shixinfa”
void add(int a,int b);
void sub();
/class Tuxing{
double width,height;
Tuxing(width,height){}
public:
double getArea(){
cout<<“1111”<<endl;
return width
height;
}

};/
/class Changfangxing::Tuxing{
double length;
Changfangxing(width,height,length){}
public:
double getArea(){
cout<<“222”<<endl;
return width
height
length;
}
};*/

class Adddmeo{

public:
double first;
double second;
static int number;
void sub(){
cout<<“ab”<<endl;
}
int foreachdemo(int n){
if(n1||n2){
return 1;
}
else{
return 3;
}
}

/* Adddemo(){
first=0;
second=0;
}
*/

//Adddemo(double first,double second):first(first),second(second){}

/*public:
void sub(){
cout<<first-second<<endl;
}
*/
};
int Adddmeo::number=22;
class Data{
public:
int a;
int b;
Data(int i,int j){
a=i;
b=j;
}
Data(){
a=3;
b=6;
}
};
class Shape{
public:
int width;
int length;
public:
void setwidth(int w){
width=w;
}
public:
void setlength2(int l){
length=l;
}
};

class Reacalge:public Shape{
public:
int getArea(){
return width*length;
}

};
class Box{
public:
int width;
int height;
int length;
Box(){};
Box(int width1,int height1,int length1){
height=height1;
width=width1;
length=length1;
};
int getarea(){
return lengthheightwidth;
}
};
int main(){
Reacalge reacalge;
reacalge.setwidth(4);
reacalge.setlength2(5);
cout<<“长方形面积”<<reacalge.getArea()<<endl;
Box box1;
Box box(2,3,4);
box1.width=1;
box1.length=2;
box1.height=3;
cout<<“面结”<<box.getarea()<<endl;
//Box box2(2,3,4);
cout<< box1.getarea()<<endl;
enum weekday {sun=1,mon,tue,wed,thu,fri,sat} day; //从1开始
int k;
printf(“请输入今天星期几(1–7):”);
scanf("%d",&k);
day=(enum weekday)k;
int B[7];
//banlance={3,4,5,66,77,88};
for (int count = 0; count < 7; count++)
cout << B [count] << " ";
double balance[6]={3,4,5,6,7,8};
for(int i=0;i<6;i++){
cout<<balance[i]<<endl;
}
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
};

 Books Book1;        // 定义结构体类型 Books 的变量 Book1
    Books Book2;        // 定义结构体类型 Books 的变量 Book2
    // Book1 详述
    strcpy( Book1.title, "C++ 教程");
    strcpy( Book1.author, "Runoob");
    strcpy( Book1.subject, "编程语言");
    Book1.book_id = 12345;
    // 输出 Book1 信息
    cout << "第一本书标题 : " << Book1.title <<endl;
    cout << "第一本书作者 : " << Book1.author <<endl;
    cout << "第一本书类目 : " << Book1.subject <<endl;
    cout << "第一本书 ID : " << Book1.book_id <<endl;
 char gree[7]={'w','e','r','t','y','u','o'};
 cout<<gree<<endl;
 Data data(388,66);
 cout<<data.a<<data.b<<endl;
// Tuxing tx=new Changfangxing(2,3,4);
 //cout<<tx.getArea()<<endl;
 //static double number=4;
 const int count=4;
 int  count2=count-2;
 cout<<count2<<endl;
 cout<<Adddmeo::number<<endl;
 Adddmeo demo;
 demo.sub();
 int result=demo.foreachdemo(5);
 cout<<result<<endl;

// Adddmeo demo=new Adddmeo(4,5);
//demo.sub();
cout<<“hello world”<<endl;
int a=22;
int b=33;
cout<<a+b<<endl;
add(2,3);
vector test;
test.push_back(1);
test.push_back(2);
test.push_back(4);
vector::iterator it;
for(it=test.begin();it!=test.end();it++)
cout<<*it<<endl;
return 0;

}
void add(int a,int b){
cout<<a*b<<endl;
}

猜你喜欢

转载自blog.csdn.net/weixin_37565521/article/details/104723733