| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2731 人关注过本帖
标题:[求助]MM要在论坛发的5个她说难的题,求各位狠人求解!!!!
只看楼主 加入收藏
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 

// 题目5:

#include <iostream> #include <cstdlib> using namespace std;

template <typename Type>

void Bubblesort(Type * pArray,int n) { int i,j; Type temp; for(i=0;i<n;i++) { for(j=n-1;j>i;j--) { if(pArray[j]<pArray[j-1]) { temp=pArray[j]; pArray[j]=pArray[j-1]; pArray[j-1]=temp; } } } }

int main() { int test1[10] = {2,66,53,48,3,56,42,28,75,13}; double test2[6] = {1.2, 6.6, 5.3, 4.8, 3.0, 5.6};

int n_test1 = sizeof(test1) / sizeof(int); int n_test2 = sizeof(test2) / sizeof(double); void (* pf1)(int *, int); // declaration of a pointer to the function void (* pf2)(double *, int); // declaration of a pointer to the function

pf1 = Bubblesort; // pf1 points to the function

pf1(test1,n_test1); // using pointer pf1 to invoke the function

// to check the result for(int i = 0; i<n_test1; i++) { cout<<test1[i]<<" "; } cout<<endl;

pf2 = Bubblesort; // pf2 points to the function pf2(test2, n_test2); // using pointer pf2 to invoke the function // to check the result for(int j = 0; j<n_test2; j++) { cout<<test2[j]<<" "; } cout<<endl; system("pause"); return 0; }


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2004-10-03 00:08
bcomer
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2004-9-13
收藏
得分:0 
以下是引用kai在2004-10-02 21:27:57的发言:

// 题目1:

#include <iostream> #include <cstdlib> using namespace std;

template <typename T> void invert(T * x, int i, int j) { T t; if(i<j) { t = *(x+i); *(x+i) = *(x+j); *(x+j) = t; invert(x, i+1, j-1); } }

int main() { // to test this subfunction double a[10] = {0.1,1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9}; int i; invert(a, 0, 9);

// display the result for(i = 0; i<10; i++) { cout<<a[i]<<","; } cout<<endl; system("pause"); return 0; }

我的编译软件是VISUAL STUDIO6.0下的VISUAL C++6.0无法看到展示的结果

system("pause");还需要什么前提吗?

2004-10-03 10:03
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
去掉这行就行了!
2004-10-03 10:47
不懂
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2004-10-2
收藏
得分:0 

谢谢楼上的大哥们哦~~

不过现在还有3 4题没有`~

谢谢大家把没有做的题目补上~~

谢谢~~

2004-10-03 13:47
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

斑竹啊!!留点机会给我们这些小弟啊!

你一个人全写了,我做都不想做了1!


2004-10-03 15:01
kuangjingbo
Rank: 1
等 级:新手上路
帖 子:312
专家分:0
注 册:2004-4-24
收藏
得分:0 

kai好敬业!


永不放弃!
2004-10-03 15:21
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

本题4

由于本人刚刚学C++ ,所以程序写的比较差,请见谅!!

(已经在本人VC中调试通过)

#include<iostream.h> #include<math.h> int main() { double a; double b; double c; double d; double Dirt; double X1; double X2; cout<<"请输入系数 a:"; cin>>a; cout<<"请输入系数 b:"; cin>>b; cout<<"请输入系数 c:"; cin>>c; Dirt=b*b-4*a*c; if(Dirt<0) { cout<<"本方程无解"<<endl; } else { d=sqrt(Dirt); X1=(d-b)/(2*a); X2=(-d-b)/(2*a); cout<<X1<<endl; cout<<X2<<endl; } return 0; }


2004-10-03 15:39
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

本题 3

(但是有个地方错,麻烦大家改改,我的结果为什么都是7啊?)

#include<iostream.h> class NODE { NODE *NEXT; char DATA; public: friend class LIST; }; class LIST { public: LIST(); void Build_Forward(char Data);//表前插入 int Number_list();//计数函数 ~LIST(){}; private: NODE *HEAD; }; LIST::LIST() { HEAD=NULL; } void LIST::Build_Forward(char Data) { NODE *P; P=new NODE; P->NEXT=HEAD; HEAD=P; } int LIST::Number_list() { NODE *p; int e; e=0; p=HEAD; while(p!=NULL) { e++; p=p->NEXT; } return e; } void main() {

char c; LIST s; cout<<" the data in the list is:"<<endl; for(int i=0;i<7;i++) { cin.get(c); s.Build_Forward(c); } cout<<s.Number_list(); }

图片附件: 游客没有浏览图片的权限,请 登录注册

2004-10-03 16:14
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 

因为这句

for(int i=0;i<7;i++)

2004-10-03 17:44
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

嗯!我知道是这句,但是它的作用是建立7个链表,你只要输入少于7个的字母就可以的了,

但不知为何会这样啊!??


2004-10-03 18:21
快速回复:[求助]MM要在论坛发的5个她说难的题,求各位狠人求解!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016610 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved