初学C++,有道题目帮忙解答下,可以+分.

来源:百度知道 编辑:UC知道 时间:2024/06/05 16:34:30
7、 编写程序,要求主函数定义一个有M行N列的二维字符数组,并分别调用四个函数实现:
(1) 从键盘向数组输入n个字符串;
(2) 用插入排序的方法对n个字符进行升序排列。
(3) 用二分法在已排序的n个字符上查找某字符串,如果找到则返回字符串所在的行标,若查找失败则返回-1。
(4) 输出数组中的n个字符串。
注:主函数中,排序前后的字符串均要输出。

PS:本人初学C++,朋友们请尽量用简单的语句写。如果简明易懂的话,追分.

在这里,我先谢谢大家了.

#include<iostream>
#include<cstdlib>
#define M 10
#define N 20
using namespace std;
void input(char arr[][N],int n,int y);
void taxis(char arr[][N],int n,int y);
void swap_l(char a[],char b[],int n);
int lookup(char arr[][N],int begin,int end,char *str);
void main()
{
char arr[M][N];
int n;
char *str;
str=new char[20];
int row;

cout<<"please input the num of you want to input(the num would smaller than "<<M<<"):";
cin>>n;

input(arr,n,N);
cout<<endl;
cout<<"the strings you input is:"<<endl;
for(int i=0;i<n;i++)
{
cout<<arr[i]<<endl;
}
taxis(arr,n,N);
cout<<endl;
cout<<"After order:"<<endl;
for(int i=0;i<n;i++)
{
cout<<arr[i]<<endl;
}
cout<<&qu