王朝知道
分享
 
 
 

我想学习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;

}

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
如何用java替换看不见的字符比如零宽空格&#8203;十六进制U+200B
 干货   2023-09-10
网页字号不能单数吗,网页字体大小为什么一般都是偶数
 干货   2023-09-06
java.lang.ArrayIndexOutOfBoundsException: 4096
 干货   2023-09-06
Noto Sans CJK SC字体下载地址
 干货   2023-08-30
window.navigator和navigator的区别是什么?
 干货   2023-08-23
js获取referer、useragent、浏览器语言
 干货   2023-08-23
oscache遇到404时会不会缓存?
 干货   2023-08-23
linux下用rm -rf *删除大量文件太慢怎么解决?
 干货   2023-08-08
刀郎新歌破世界纪录!
 娱乐   2023-08-01
js实现放大缩小页面
 干货   2023-07-31
生成式人工智能服务管理暂行办法
 百态   2023-07-31
英语学习:过去完成时The Past Perfect Tense举例说明
 干货   2023-07-31
Mysql常用sql命令语句整理
 干货   2023-07-30
科学家复活了46000年前的虫子
 探索   2023-07-29
英语学习:过去进行时The Past Continuous Tense举例说明
 干货   2023-07-28
meta name="applicable-device"告知页面适合哪种终端设备:PC端、移动端还是自适应
 干货   2023-07-28
只用css如何实现打字机特效?
 百态   2023-07-15
css怎么实现上下滚动
 干货   2023-06-28
canvas怎么画一个三角形?
 干货   2023-06-28
canvas怎么画一个椭圆形?
 干货   2023-06-28
canvas怎么画一个圆形?
 干货   2023-06-28
canvas怎么画一个正方形?
 干货   2023-06-28
中国河南省郑州市金水区蜘蛛爬虫ip大全
 干货   2023-06-22
javascript简易动态时间代码
 干货   2023-06-20
感谢员工的付出和激励的话怎么说?
 干货   2023-06-18
 
>>返回首页<<
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有