1. 定义一个数组stu[10]存放10个学生的成绩,从键盘输入数据,要求用指针实现 2. 将数组stu[10]的内容输

如题所述

第1个回答  2011-06-11
#include <iostream>
#include <iostream>
using namespace std;
void sort(float stu[10]);
int main()
{
cout<<"Input the string please:"<<endl;
char *pStr;
pStr=new char[];
cin.getline(pStr,80);
cout<<pStr<<endl;

float stu[10];
cout<<"Please input the score:"<<endl;
for(int i=0;i<10;i++)
cin>>stu[i];
float *pStu;
pStu=stu;
for(int i=0;i<10;i++)
{
cout<<*pStu<<'\t';
pStu++;
}
sort(stu);

pStu=stu;
cout<<"排序后的学生成绩为:"<<endl;
for(int i=0;i<10;i++)
{
cout<<*pStu<<'\t';
pStu++;
}

delete [] pStr;

system("PAUSE");
return 0;

}
void sort(float stu[10])
{
float temp;
for(int i=0;i<10;i++)
{
for(int j=i;j<10;j++)
{
if(stu[i]<stu[j])
{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
}
}

}
第2个回答  2011-06-08
#include<iostream.h>
void main()
{
int i;
float stu[10],*p;
p=stu;
cout<<"请输入十个学生的成绩:\n";
for(i=0;i<10;i++)
cin>>*(p+i);
for(i=0;i<10;i++)
cout<<*(p+i)<<' ';
cout<<endl;
}本回答被网友采纳
第3个回答  2011-06-06

#include <iostream>
#include <iostream>
using namespace std;
void sort(float stu[10]);
int main()
{
cout<<"Input the string please:"<<endl;
char *pStr;
pStr=new char[];
cin.getline(pStr,80);
cout<<pStr<<endl;

float stu[10];
cout<<"Please input the score:"<<endl;
for(int i=0;i<10;i++)
cin>>stu[i];
float *pStu;
pStu=stu;
for(int i=0;i<10;i++)
{
cout<<*pStu<<'\t';
pStu++;
}
sort(stu);

pStu=stu;
cout<<"排序后的学生成绩为:"<<endl;
for(int i=0;i<10;i++)
{
cout<<*pStu<<'\t';
pStu++;
}

delete [] pStr;

system("PAUSE");
return 0;

}
void sort(float stu[10])
{
float temp;
for(int i=0;i<10;i++)
{
for(int j=i;j<10;j++)
{
if(stu[i]<stu[j])
{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
}
}

}
相似回答