求C++高手帮忙遍几个小程序,急求有一个是一个啊!

作者&投稿:兆昆功 (若有异议请与网页底部的电邮联系)
谁有比较有趣的用C++写的小程序啊!有帮忙传两个啊,谢谢啊!简单点的啊,我是菜鸟!~

#include
using namespace std;
void Move(int a[] ,int n,int k)
{

int len=n-1;
int i,j,temp=0;
for(i=0;i<k;i++)
{
temp=a[len];
for(j=len;j>0;j--)
a[j]=a[j-1];
a[0]=temp;
}
}
int main()
{
int a[100];
int i,n,k;
cin >> n;
if(n<100)
{
for(i=0;i<n;i++)
cin >> a[i];
}
cin >> k;
Move(a,n,k);
for(i=0;i<n;i++)
cout << a[i] << " ";
return 0;
}

这是循环移动的 希望你采纳答案

#include
using namespace std;
typedef double number;
inline double sqr(const double &x){ return x*x; };
class point
{
private:
number x,y;
public:
point():x(0),y(0){}//用0分别初始化x,y,就是point(){ x=0;y=0 }下同
point(number _x,number _y):x(_x),y(_y){}
point(const point &another):x(another.x),y(another.y){}
~point(){}//没在堆内申请空间,不用管析构函数,甚至可以不写

friend number length(const point &a,const point &b){ return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); }
//因为line里面求两点距离要访问点内的数据,干脆加个友元 ,sqrt是cmath里的,sqr是才定义的
};
class line
{
private:
point beg,end;
public:
line(point b,point e):beg(b),end(e){}
~line(){}

number distance(){ return length(beg,end); }
};
class complex
{
private:
number r,ir;//实,虚
public:
complex():r(0),ir(0){}//初始化
complex(number _r,number _ir=0):r(_r),ir(_ir){}//实数情况_ir=0 例complex a(3.5);
complex(const complex &another):r(another.r),ir(another.ir){}
~complex(){}

complex operator+(const complex &b){ return complex(r+b.r,ir+b.ir); }//重载运算符 a.operator+(b) 就是a+b
complex operator-(const complex &b){ return complex(r-b.r,ir-b.ir); }
};
#include
class people
{
private:
int number;
string name;
int sex;//1 for male,2 for famale
class Date{//format:****.**.**
public:
unsigned year,month,day;
Date(unsigned y,unsigned m,unsigned d):year(y),month(m),day(d){}
} birthday;//同时定义类和申请对象 相当于class Date{......};Data birthday; 因为内嵌懒得用private了
public:
people():number(-1),name(""),sex(0),birthday(0,0,0){}//Date的构造函数有三参数
people(const people &b):number(b.number),name(b.name),sex(b.sex),birthday(b.birthday.year,b.birthday.month,b.birthday.day){}
//成员函数
people &set(int n,const string &nm,int s,unsigned year,unsigned month,unsigned day)
{
number=n;
name=nm;
sex=s;
birthday.year=year;
birthday.month=month;
birthday.day=day;
return(*this);
}
people &show()
{//就用C的printf算了,用ostream的写在下面
string _sex;
switch(sex)
{
case 0:_sex="未知";break;
case 1:_sex="男 ";break;
case 2:_sex="女 ";break;
}
printf("%d %s %s 出生日期:%d/%d/%d",number,&name[0],&_sex[0],birthday.year,birthday.month,birthday.day);
return (*this);
}
//运算符重载
friend ostream &operator<<(ostream &o,const people&p)
{
o<<p.number<<' '<<p.name<<' '<<(p.sex==0?"未知":(p.sex==1?"男 ":"女 "))<<" 出生日期:"<<p.birthday.year<<'/'<<p.birthday.month<<'/'<<p.birthday.day;
//用三元运算符 ?:作判断省去if或switch
return o;
}
};
int main()
{
people a;
a.set(7,"kevin",1,1992,4,12);
people b(a);
b.show();
cout<<endl<<a<<endl;
system("pause");
return 0;
}
//不会吧,我用devcpp编译成功运行正确
//你把便一起编译器、错误都给我吧

1.以下程序的功能是将用户从键盘输入(输入‘#’时结束)的若干大写字母转换成对应的小写字母。请补充完整tocaps函数。
#include <stdio.h>
char tocaps (char ch)
{
在此补充内容:if(ch>='A'&&ch<='Z')
ch=ch+32;
return ch;
}
main( )
{ char c ,d ;
c=getchar( );
while(c!='#')
{ d= tocaps(c) ; putchar (d ); c=getchar(); }
}

2.以下程序的功能是:用户从键盘输入两个float型数据a 和 b,计算并输出a除以b的商。程序中有语法错误,请修改。

#include<stdio.h>
float cal( float a,float b )
{
float x;
x= a/ b;
return x;
}
main( )
{ float a, b ;
scanf( " %f %f", &a, &b );
printf( " % .2f除以 %.2f 的商是:%.2f\n ", a, b, cal (a,b) );
}

3.下面程序的功能是输出结构体数组的内容。请将程序补充完整
struct
{ char name[10];
char sex;
int age ;
}p[3]={ { "Lee", ' f ' , 46 },{ "Mon", ' m ' , 62 },{ "Fan", ' f ' , 25 } };
main ( )
{
在此补充内容:int i;
for(i=0;i<=2;i++)
printf("%s %c %d\n",p[i].name,p[i].sex,p[i].age);
}

4.下面程序的功能是统计8名学生中数学和英语成绩均大于等于60分的人数。请将程序补充完整。
struct st
{ int num;
float s[2];
};
int fun (struct st stu[ ] )
{

在此补充内容: int n=0,i;
for(i=0;i<=7;i++)
if(stu[i].s[0] >=60.0 && stu[i].s[1] >=60.0 ) n++;
return n;
}
main ()
{struct st stu[8]={ { 1,82.5,78 },{ 2,60,54.5},{ 3,90,86.5 },{ 4,76.5,82},{ 5,65,46 },{ 6,73.5,64 },{ 7,54.5,55 },{ 8,65,78.5 } };
int n;
n=fun ( stu ) ;
printf ( " The number beyond 60:%-d\n " , n );
}

第一个的
#include <stdio.h>
char tocaps (char ch)
{
char st;
st=ch+32;
return st;
}
void main( )
{ char c,d;
printf("请输入大写字母,以'#'号结束输入:");
c=getchar( );
while(c!='#')
{
d=tocaps(c);
putchar(d);
c=getchar();
}
}
2.以下程序的功能是:用户从键盘输入两个float型数据a 和 b,计算并输出a除以b的商。
程序中有语法错误,请修改。

#include<stdio.h>
float cal(float a, float b )
{
float x;
x= a/ b;
return x;
}
void main( )
{
float a,b;
scanf(" %f%f", &a, &b );
printf( " % .2f除以 %.2f 的商是: %.2f\n ", a, b, cal(a,b) );
}
3.下面程序的功能是输出结构体数组的内容。请将程序补充完整
#include<stdio.h>
struct
{ char name[10];
char sex;
int age ;
}p[3]={{ "Lee", ' f ' , 46 },{ "Mon", ' m ' , 62 },{ "Fan", ' f ' , 25 } };
void main ( )
{
int i;
for(i=0;i<=2;i++)
printf("%s %c %d\n",p[i].name,p[i].sex,p[i].age);
}

4.下面程序的功能是统计8名学生中数学和英语成绩均大于等于60分的人数。请将程序补充完整。
#include<stdio.h>
struct st
{ int num;
float s[2];
};
int fun (struct st stu[ ] )
{
int n=0,i;
for(i=0;i<=7;i++)
if(stu[i].s[0] >=60.0 && stu[i].s[1] >=60.0 ) n++;
return n;
}
void main ()
{struct st stu[8]={ { 1,82.5,78 },{ 2,60,54.5},{ 3,90,86.5 },{ 4,76.5,82},{ 5,65,46 },{ 6,73.5,64 },{ 7,54.5,55 },{ 8,65,78.5 } };
int n;
n=fun ( stu ) ;
printf ( " The number beyond 60: %-d\n " , n );
}

已发126 是一个通讯录程序 分模块的 应该比较好理解 有不懂的地方可以hi我 在vc 中调试通过 以前写过几个的几个,看看合适吗 1 字符串逆序 2

1.
#include <stdio.h>
char tocaps (char ch)
{
//在此补充内容
if(ch>='A'&&ch<='Z')
ch=ch+32;
return ch;
}
main( )
{ char c ,d ;
c=getchar( );
while(c!='#')
{ d= tocaps(c) ; putchar (d ); c=getchar(); }
}

2.
#include <stdio.h>
float cal ( float a, float b )
{
float x;
x= a/ b;
return x;
}
main( )
{ float a, b ;
scanf( " %f%f", &a, &b );
printf( " % .2f除以 %.2f 的商是:%.2f\n ", a, b, cal (a,b) ); }

3.
struct
{ char name[10];
char sex;
int age ;
}p[3]={ { "Lee", ' f ' , 46 },{ "Mon", ' m ' , 62 },{ "Fan", ' f ' , 25 } };
main ( )
{
int i;
for(i=0;i<=2;i++)
printf("%s %c %d\n",p[i].name,p[i].sex,p[i].age);

}

4.
struct st
{ int num;
float s[2];
};
int fun (struct st stu[ ] )
{

// 在此补充内容
int count,i;
for(i=1;i!=sizeof(stu);i++)
{
if (stu[i].s[0]>=60&&stu[i].s[1]>=60)
count++;
}
return count;
}
main ()
{struct st stu[8]={ { 1,82.5,78 },{ 2,60,54.5},{ 3,90,86.5 },{ 4,76.5,82},{ 5,65,46 },{ 6,73.5,64 },{ 7,54.5,55 },{ 8,65,78.5 } };
int n;
n=fun ( stu ) ;
printf ( " The number beyond 60:%-d\n " , n );
}

1.
#include <stdio.h>
char tocaps (char ch)
{
ch=ch - 32;
reurn ch;
}
main( )
{ char c ,d ;
c=getchar( );
while(c!='#')
{ d= tocaps(c) ; putchar (d ); c=getchar(); }
}

2.
#include<stdio.h>
float cal( float a,float b )
{
float x;
x= a/ b;
return x;
}
main( )
{ float a, b ;
scanf( " %f %f", &a, &b );
printf( " % .2f除以 %.2f 的商是:%.2f\n ", a, b, cal (a,b) );
}

3.
struct
{ char name[10];
char sex;
int age ;
}p[3]={ { "Lee", ' f ' , 46 },{ "Mon", ' m ' , 62 },{ "Fan", ' f ' , 25 } };
main ( )
{
int i;
for(i=0;i<=2;i++)
printf("%s %c %d\n",p[i].name,p[i].sex,p[i].age);

}

4.
struct st
{ int num;
float s[2];
};
int fun (struct st stu[ ] )
{
int n=0,i;
for(i=0;i<=7;i++)
if(stu[i].s[0] >=60.0 && stu[i].s[1] >=60.0 ) n++;
return n;
}
main ()
{struct st stu[8]={ { 1,82.5,78 },{ 2,60,54.5},{ 3,90,86.5 },{ 4,76.5,82},{ 5,65,46 },{ 6,73.5,64 },{ 7,54.5,55 },{ 8,65,78.5 } };
int n;
n=fun ( stu ) ;
printf ( " The number beyond 60:%-d\n " , n );
}


高手帮忙看下这个c语言程序为什么几个if语句都执行
感觉是内存错误。scanf("%f,%f",&lower,&upper);这个地方赋值未成功。这样就对了 include<stdio.h> include<math.h> include<ctype.h> include<string.h> main(){ double i,area;double a,b,c,lower,upper,step;char s[3];printf("一次函数:lin\\n二次函数:qua\\n指数函数:exp\\n幂函数...

请高手帮忙写下C语言程序
第6题目(我本来是日文的,所以有乱码自己改吧)include <stdio.h> int main(void){ int n;int i=0;int max=0;int min=101;int z=0;int p=2;while(1!=p){++i;printf("成绩输入:\\n");scanf("%d",&n);if(n<50) printf("D\\n");else { if(n<65) printf("C ");else if(n...

c语言 求教高手帮忙解答 关于指针
for为s数组赋值。s0值未知。s1到s5为2,3,4,5,6。输出f(s,4,n)。s数组的首地址被局部指针变量s接收。其他两个局部变量(f的形参)a=4,n=5。再看f函数体:*s=a。也就是*s=4。s指向main函数中的s数组首地址。也就是s0的地址。所以s数组的六个值为4,2,3,4,5,6。再看j=...

C++高手帮忙!今天想了很久还是想不出洗牌的的原理.上百度下了个程序也...
这是相对比较低效的,每次随即生成一张牌,遍历一遍,原来没有生成过则加入牌组,否则丢弃。include <stdio.h> include <math.h> include <stdlib.h> include int main(){ int card[52];int a,j,n,i=0,nosame=1;char c;randomize(); \/\/只要初始化一次就行,否则一秒内的随机数是一...

数据结构(C语言版) 图的遍历和拓扑排序
任务:给定一个有向图,实现图的深度优先, 广度优先遍历算法,拓扑有序序列,并输出相关结果。功能要求:输入图的基本信息,并建立图存储结构(有相应提示),输出遍历序列,然后进行拓扑排序,并测试该图是否为有向无环图,并输出拓扑序列。 麻烦哪位高手帮忙下 谢谢~! 展开  我来答 3...

一道C语言编程题,超急!!今晚截至!!望高手帮忙
include "iostream"\/\/标准输入输出 include <vector>\/\/vector头文件 using namespace std;\/\/命名空间 int main(){ vector<int> vec;for(int i=0;i<10;++i){ int m_a;cin>>m_a;\/\/输入一个整形到m_a vector<int>::iterator pos=vec.begin();\/\/指向vec的第一个元素 while(pos!=vec....

用c语言编程输出方程x2+y2+z2=1989的所有正整数解,高手帮忙,谢谢
x2是指x的平方,还是2x,还是x2就是变量?一个简单易懂的方法,不考虑查询速度 int x2,y2,z2;x2=y2=z2=0;for (x2 = 0;x2<=1989;x2++){ for(y2 = 0 ;y2<=1989;y2++){ for(z2 =;z2<=1989;z2++){ if( 1989 == (x2+y2+z2)){ printf("x2=%d,y2=%d,z2=...

程序出错,关于C语言,高手帮忙看一下
scanf("%d,%d,%d",&a,&b,&c); 当你在%d之间用","时,输入时也要在各个数之间有",",这是C语言的规定,或者你不用",",用" "也行.还有就是你为什么要把void swap(int *pt1,int *pt2){ int temp;temp=*pt1;pt1=*pt2;pt2=temp;} 输入两遍呢? 这样改下来就没错误了!以后可要...

...需要构建一棵哈夫曼树。请高手帮忙给出实际的编程代码。。感激不...
int i,n,c,f,k,x;n = ht[0].weight;for ( i=1; i<=n; i++ ){ d.start = n+1;\/*d.start为栈项*\/ c = i; \/*c存放当前结点*\/ f = ht[i].parent;\/*f存放当前结点的父结点*\/ while ( f != 0 ){ if ( ht[f].left == c ) \/*若当前结点在其父结点的左边时*...

请高手帮忙设计一下这个c语言程序,用多种方式!
for (c=0;c<10;c++)if ((a==5||b==5||c==5)&&(a+b+c)%3==0)num++;printf("符合要求的数有%d个\\n",num);} 3.\/ 从排列组合的角度来算,任取3位数中的一个为5(以下代码令个位数取5),计算符合是3的倍数的个数设为num,将该数乘以3倍后3*num,扣掉多计算两遍的555,...

蓝山县17175993506: 求C++高手帮忙编几个简单的程序
雷羽立迈: for函数: #include<iostream> using namespace std; int main() { int i,N; double result=0; cout<<"输入N:"<<endl; cin>>N; for(i=1;i<N+1;i++) result += (double)1/i; cout<<result<<endl; return 0; }

蓝山县17175993506: 求C++方面的高手帮我看下这个小程序. -
雷羽立迈: #include void main() {char c;int a=0,b=0,m=0,n=0;正确的程序是: #include int main() { char c; int a=0,...

蓝山县17175993506: 我在学编程用的是C++,高手给我几个小程序的代码吧!!
雷羽立迈: 服了,不懂能不能谦虚点.拿这破东西来糊弄人啊?晕死. 给你个基于线程的程序. C++ pthread 小例子2008-12-04 15:00//header //thread.h #ifndef THREAD_H #define THREAD_H #include <iostream> using namespace std; class Thread { ...

蓝山县17175993506: 求大神帮忙编一个小程序,用vc++编
雷羽立迈: #include<stdio.h>#include<math.h> int main() { int sushu( int k); int j,geshu=0; for(j=103;j<999;j=j+10) { if(sushu(j)==1) { printf("%d\n",j); geshu++; } } printf("%d\n",geshu); return 0; } int sushu(int k) { int i; for(i=2;i<sqrt(k);i++) { if(k%i==0) return 0; } return 1; }

蓝山县17175993506: C++求帮编程!小程序,急
雷羽立迈: #include <iostream> using namespace std; int GetValue(int i,int j,int n) { int min =0; if(i >= j) min = j; else min = i; if((n-i) <=(n-j)) { if(n-i < min) min = n-i; } else { if(n-j < min) min = n-j; } return min + 1; } int _tmain(int argc, _TCHAR* argv[]) { int N; cin>>N...

蓝山县17175993506: 急求C++小程序 -
雷羽立迈: 请看下面程序:#include#include void xopy();void prime();void sort(int*,int);void printstar(int);void main(){ char c='1'; while(c!='5'){ cou...

蓝山县17175993506: C++简单小程序跪求高手解答 -
雷羽立迈: int main(){ complex c1(10,20),c2();//这错了 可以c2()去掉括号,或c2(1,2)既是给它个初值 错误提示是error C2659: '=' : overloaded function as left operand 错误赋值...

蓝山县17175993506: 跪求C++大神帮忙编个程序!急需!!!感激不尽!!! -
雷羽立迈: 说实话,比较简单. 我这会想休息一下,就简单给你写个框子吧. typedef double (*Func) (double x); //定义一个函数指针,注意我只简单写一个参数的函数指针.double e_pow_x(double x) //e^x {return ......;// 自己找数学库中的函数 }double ...

蓝山县17175993506: 求大神帮我用c++语言写个循环的小程序..如果运行没错误的话会加分的,急求! -
雷羽立迈: 看看这个程序可否满足要求:#include<iostream>using namespace std;void main(){ int lon,wid; int i,j,r; cout <<"How many tiles LONG would you like the pattern to be? "; cin >>lon; cout <<"How many tiles WIDE would you like the pattern to be? ...

蓝山县17175993506: 求c++小程序 -
雷羽立迈: #includemain() { int a,b; /* 定义a,b两个整形变量用于输入两个整数 */ int *point_1,*point_2,*temp_point; /* 定义三个指针变量 */ scanf("%d,%d",&a,&b); /* 格式化输入a,b的值 */ point_1=&a; /* 把指针变量point_1的值指向变量a的地址 */ ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网