分享
 
 
 

我想学习C++编程,想要多读别人的代码,请问去那里可以下程序,或者有这样的书吗

王朝知道·作者佚名  2012-07-12
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
參考答案:

看看这几个,或许对你有帮助:

#include<iostream.h>

void main()

{ int a[20][20],n,i,j,sum1=0,sum2=0;

cout<<"请确定二阶矩阵的大小:"<<"n=";

cin>>n;

if(n>20)

{cout<<"矩阵过大,请重新定义"<<"n=";cin>>n;}

cout<<"请输入数据:"<<endl;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

cin>>a[i][j];

cout<<endl;

for(i=0;i<n;i++)

{sum1=sum1+a[i][i];sum2=sum2+a[n-1-i][n-1-i];}

cout<<"正对角线之和="<<sum1<<endl<<"副对角线之和="<<sum2<<endl;

}

#include<iostream.h>

void main()

{

char a[40],b[40],c[80];

int i,j;

cout<<"请输入第一个小于40个字符的字符串:";

cin>>a;

cout<<"请输入第二个小于40个字符的字符串:";

cin>>b;

for(i=0;a[i]!='\0';i++)

c[i]=a[i];

for(j=0;b[j]!='\0';j++)

c[i+j]=b[j];

c[i+j]='\0';

cout<<"两字符串连接后为:"<<c<<endl;

}

#include<iostream.h>

void main()

{void max_min(float *x,int n);

float a[100],*pt;

int i,n;

cout<<"Please define the size of the arry:n=";cin>>n;

if(n>100)

{cout<<"error!n<=100\nPlease redefine n=";cin>>n;}

cout<<"Enter data:";

for(i=0;i<n;i++)

cin>>a[i];

pt=a;

max_min(pt,n);

}

void max_min(float *x,int n)

{float *p,min,max,i=0,j,k=0,f;

min=*x;

max=*x;

for(p=x;p<x+n;p++,i++)

if(*p<=min)

{min=*p;j=i;}

cout<<endl<<"最小数为:"<<min<<endl<<"其下标为:"<<j;

for(p=x;p<x+n;p++,k++)

if(*p>=max)

{max=*p;f=k;}

cout<<endl<<"最大数为:"<<max<<endl<<"其下标为:"<<f<<endl;

}

#include <iostream.h>

const float PI = 3.14159;

class Circle

{

private:

float radius;

public:

Circle(float r); //构造函数

float Circumference(); //圆周长

float Area(); //圆面积

};

Circle::Circle(float r)

{radius=r;}

// 计算圆的周长

float Circle::Circumference()

{return 2 * PI * radius;}

// 计算圆的面积

float Circle::Area()

{return PI * radius * radius;}

void main()

{

float radius,ference,area;

cout<<"Enter the radius of the circle: ";

cin>>radius;

Circle c(radius);

Circle s(radius);

ference=c.Circumference();

area=s.Area();

cout<<"The Circumference of the circle is:"<<ference<<endl;

cout<<"The Area of the circle is:"<<area<<endl;

}

//定义一个学生类,使用构造函数和析构函数实现对数据的输入、输出

#include<iostream.h>

#include<string.h>

int i=0;

int n;

class student

{public:

student(int s_id,char s_name[20],int s_age);

~student();

private:

char name[20];

int id;

int age;

};

student::student(int s_id,char s_name[20],int s_age)

{

id=s_id;

strcpy(name,s_name);/*特别注意*/

age=s_age;

}

student::~student(void)

{cout<<"The student's information: "<<"id="<<id

<<" name="<<name<<" age="<<age<<endl<<"NEXT:"<<endl;

}

void main()

{

int n,s_id,s_age;

char s_name[20];

cout<<"Please define the number of the students:N=";

cin>>n;

for(i=0;i<n;i++)

{

cout<<"Enter the student's id:";

cin>>s_id;

cout<<"Enter the student's name:";

cin>>s_name;

cout<<"Enter the student's age:";

cin>>s_age;

student s(s_id,s_name,s_age);/*构造函数调用之后,隐含析构函数调用*/

}

cout<<"TASK OVER !"<<endl;

}

//定义一个学生类,使用构造函数和析构函数实现对数据的输入、输出

#include<iostream.h>

#include<string.h>

int i=0;

int n;

class student

{public:

student(int s_id,char s_name[20],int s_age);

~student();

private:

char name[20];

int id;

int age;

};

student::student(int s_id,char s_name[20],int s_age)

{

id=s_id;

strcpy(name,s_name);/*特别注意*/

age=s_age;

}

student::~student(void)

{cout<<"The student's information: "<<"id="<<id

<<" name="<<name<<" age="<<age<<endl<<"NEXT:"<<endl;

}

void main()

{

int n,s_id,s_age;

char s_name[20];

cout<<"Please define the number of the students:N=";

cin>>n;

for(i=0;i<n;i++)

{

cout<<"Enter the student's id:";

cin>>s_id;

cout<<"Enter the student's name:";

cin>>s_name;

cout<<"Enter the student's age:";

cin>>s_age;

student s(s_id,s_name,s_age);/*构造函数调用之后,隐含析构函数调用*/

}

cout<<"TASK OVER !"<<endl;

}

//定义一个学生类,使用构造函数和析构函数实现对数据的输入、输出

#include<iostream.h>

#include<string.h>

int i=0;

int n;

class student

{public:

student(int s_id,char s_name[20],int s_age);

~student();

private:

char name[20];

int id;

int age;

};

student::student(int s_id,char s_name[20],int s_age)

{

id=s_id;

strcpy(name,s_name);/*特别注意*/

age=s_age;

}

student::~student(void)

{cout<<"The student's information: "<<"id="<<id

<<" name="<<name<<" age="<<age<<endl<<"NEXT:"<<endl;

}

void main()

{

int n,s_id,s_age;

char s_name[20];

cout<<"Please define the number of the students:N=";

cin>>n;

for(i=0;i<n;i++)

{

cout<<"Enter the student's id:";

cin>>s_id;

cout<<"Enter the student's name:";

cin>>s_name;

cout<<"Enter the student's age:";

cin>>s_age;

student s(s_id,s_name,s_age);/*构造函数调用之后,隐含析构函数调用*/

}

cout<<"TASK OVER !"<<endl;

}

//编写一将编号、姓名的输入和显示设计成一个类person,并作为student和teacher的基类,

#include<iostream.h>

int i=0;

int n;

class person

{public:

void getid_name();

void putid_name();

private:

char name[20];

int id;

};

class student:public person

{public:

void getscore_classes();

void putscore_classes();

private:

int score;

int classes;

};

class teacher:public person

{public:

void getpost_depart();

void putpost_depart();

private:

char post[20];

char depart[20];

};

void person::getid_name()

{cout<<"id:";cin>>id;

cout<<"name:";cin>>name;

}

void person::putid_name()

{cout<<"id="<<id<<" name="<<name<<" ";}

void student::getscore_classes()

{cout<<"score:";cin>>score;

cout<<"classes:";cin>>classes;

}

void student::putscore_classes()

{cout<<"score="<<score<<" classes="<<classes<<endl;}

void teacher::getpost_depart()

{cout<<"post:";cin>>post;

cout<<"depart:";cin>>depart;

}

void teacher::putpost_depart()

{cout<<"post="<<post<<" depart="<<depart<<endl;}

void main()

{ char flag;

student s;

teacher t;

cout<<"Please define the number of the persons:N=";

cin>>n;

cout<<"The type of people :t=teacher,s=student?";

cin>>flag;

if(flag=='s')

for(i=0;i<n;i++)

{cout<<"NO."<<i+1<<endl;

s.getid_name();

s.getscore_classes();

cout<<"The student's information: ";

s.putid_name();

s.putscore_classes();

}

else if(flag=='t')

for(i=0;i<n;i++)

{cout<<"NO."<<i+1<<endl;

t.getid_name();

t.getpost_depart();

cout<<"The teacher's information: ";

t.putid_name();

t.putpost_depart();

}

else

cout<<"ERROR!"<<endl;

}

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有