Mar 20, 2014 at 9:57am UTC
hi. ;)
how to do this?
-
ask the user to input entries of 10x10 array. sort each column into increasing order. print out the array with sorted columns? thanks! ;)))
Last edited on Mar 20, 2014 at 10:02am UTC
Mar 20, 2014 at 11:20am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#include <iostream>
using namespace std;
#define MAT_DIM 2
class buble_sort
{
public :
void fill_arr();
void print_arr();
void sort_arr();
private :
int arr[MAT_DIM][MAT_DIM];
};
void buble_sort::fill_arr()
{
for (int i = 0; i < MAT_DIM; i++)
for (int j = 0; j < MAT_DIM; j++)
{
cout << "Enter value for element[" << i << "][" << j << "]:" ;
cin >> arr[i][j];
}
}
void buble_sort::print_arr()
{
for (int i = 0; i < MAT_DIM; i++)
{
for (int j = 0; j < MAT_DIM; j++)
cout << " " << arr[i][j];
cout << endl;
}
}
void buble_sort::sort_arr()
{
int temp;
for (int col = 0; col < MAT_DIM; col++)
for (int i = 0; i < MAT_DIM - 1; i++)
{
int continue_sort = 0;
for (int j = 0; j < MAT_DIM - i - 1; j++)
{
if (arr[j][col] > arr[j+1][col])
{
temp = arr[j][col];
arr[j][col] = arr[j+1][col];
arr[j+1][col] = temp;
continue_sort++;
}
}
if (!continue_sort)
break ;
}
}
int main()
{
buble_sort bs_obj;
bs_obj.fill_arr();
cout << "Unsorted Matrix:\n" ;
bs_obj.print_arr();
bs_obj.sort_arr();
cout << "Sorted Matrix:\n" ;
bs_obj.print_arr();
}
Last edited on Mar 21, 2014 at 3:42am UTC
Mar 20, 2014 at 11:40am UTC
omg. thank you!!! gonna run this. ;))) I have another problem...
Mar 20, 2014 at 11:43am UTC
ask the user to enter the names and population of 3 cities in metro manila. find the average of all the population that have been entered and print the names of all cities that have their population larger than the computed average. (here's the other problem. thank you in advanced. ;))) )
Mar 20, 2014 at 11:49am UTC
why don't you have go first? at least an attempt.. Before copying and pasting someone else's code and learning nothing from the process.