没有合适的资源?快使用搜索试试~ 我知道了~
C++程序设计编程实例大全
需积分: 11 7 下载量 27 浏览量
2015-08-08
11:48:03
上传
评论
收藏 529KB DOC 举报
温馨提示
试读
64页
C++程序设计编程实例大全,------------------------------ 无私分享造就开源的辉煌
资源推荐
资源详情
资源评论
C++程序编程实例大全
#include<iostream>
int main()
{
std::cout<<"hello world!";
}
#include "iostream"
using namespace std;
void main()
{
int *p;
p=new int;
*p=5;
/*p=new int(5);*/
cout<<*p;
delete p;
}
#include "iostream"
using namespace std;
void main()
{ char name[10];
cout<<"please input your name:";
cin>>name;
cout<<"the name is "<<name<<endl;
}
#include "iostream"
using namespace std;
void main()
{ char name[10];
int age;
cout<<"please input your name:";
cin>>name;
cout<<"how old are you:";
cin>>age;
cout<<"the name is "<<name<<endl;
cout<<"the age is "<<age<<endl;
}
#include "iostream"
using namespace std;
void main()
{
struct student
{
int no;
float math;
};
int n;
cin>>n;
student wang;
wang.no=n;
cin>>wang.math;
cout<<wang.no<<" "<<wang.math<<endl;
}
#include "iostream"
using namespace std;
void main()
{
int *p;
int n;
cout<<"please input the length of the array: ";
cin>>n;
if((p=new int[n])==0)
{
cout<<"can't allocate more memory, terminating"<<endl;
exit(1);
}
for(int i=0;i<n;i++)
p[i]=i*2;
cout<<"Now output the array: "<<endl;
for(i=0;i<n;i++)
cout<<p[i]<<" "<<endl;
delete []p;
}
#include "iostream"
using namespace std;
void main()
{
int *p;
int n;
cout<<"please input the length of the array: ";
cin>>n;
if((p=new int[n])==0)
{
cout<<"can't allocate more memory, terminating"<<endl;
exit(1);
}
for(int i=0;i<n;i++)
p[i]=i*i+1;
cout<<"Now output the array: "<<endl;
for(i=0;i<n;i++)
cout<<p[i]<<" ";
cout<<endl;
delete []p;
}
/* Note:Your choice is C IDE */
#include <iostream>
using namespace std;
float a=2.4;
void main()
{
int a=8;
cout<<a<<endl;
cout<<::a<<endl;
}
/* Note:Your choice is C IDE */
#include <iostream.h>
void main()
{
int num=50;
int &ref=num;
ref+=10;
cout<<"num="<<num<<endl;
cout<<"ref="<<ref<<endl;
num+=40;
cout<<"num="<<num<<endl;
cout<<"ref"<<ref<<endl;
}
/* Note:Your choice is C IDE */
#include <iostream.h>
void main()
{
int num;
int &ref=num;
num=5;
cout<<"num="<<num<<endl;
cout<<"ref="<<ref<<endl;
cout<<"&num="<<&num<<endl;
cout<<"&ref="<<&ref<<endl;
}
/* Note:Your choice is C IDE */
#include <iostream>
using namespace std;
void swap(int &x,int &y);
void main()
{
int x=5,y=6;
cout<<"before swap, x:"<<x<<" ,y:"<<y<<endl;
swap(x,y);
cout<<"after swap, x:"<<x<<" ,y:"<<y;
}
void swap(int &rx,int &ry)
{
int t=rx;
rx=ry;
ry=t;
}
#include<iostream>
//using namespace std;
void main()
/*{
double radius;
cout<<"please input radius:";
cin>>radius;
double result=radius*radius*3.14*4;
cout<<"The result is "<<(double)result<<"\n";
}
*/
{
double radius;
std::cout<<"please input radius: ";
std::cin>>radius;
std::cout<<"The result is "<<radius*radius*3.14*4<<"\n";
}
/* Note:Your choice is C IDE */
#include <iostream>
using namespace std;
int array[6][4]={{60,80,90,75},{75,85,65,77},{80,88,90,98},{89,100,78,81},{62,68,69,75},
{85,85,77,91}};
int &level(int grade[],int size,int &tA,int &tB );
void main()
{
int typeA=0,typeB=0;
int student=6;
int gradesize=4;
for(int i=0;i<student;i++)
level(array[i],gradesize,typeA,typeB)++;
cout<<"number of type A is "<<typeA<<endl;
cout<<"number of type B is "<<typeB<<endl;
}
int &level(int grade[],int size,int &tA,int &tB)
{
int sum=0;
for(int i=0;i<size;i++)
sum+=grade[i];
sum/=size;
if(sum>=80)
return tA;
else
return tB;
}
/* Note:Your choice is C IDE */
#include <iostream>
using namespace std;
float &fn2(float r)
{
float t;
t=3.14*r*r;
return t;
}
void main()
{
fn2(5.0)=12.4;
剩余63页未读,继续阅读
资源评论
qq_29016517
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功