First commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#include <iostream>
|
||||
|
||||
/*
|
||||
*This was coded by Darrel Israel
|
||||
*Do not change anything!
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
//Bubble sort algorithm
|
||||
void bubbleSortNamesAscending(string name[], int arr_size)
|
||||
{
|
||||
string temp;
|
||||
for (int i = 0; i < arr_size; i++)
|
||||
{
|
||||
for (int j = i + 1; j < arr_size; j++)
|
||||
{
|
||||
if(name[i] > name[j])
|
||||
{
|
||||
temp = name[i];
|
||||
name[i] = name[j];
|
||||
name[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const int arr_size = 10;
|
||||
int age[arr_size];
|
||||
string name[arr_size], temp;
|
||||
//for loop to ask the user for the students name and age
|
||||
for (int i = 0; i < arr_size; i++)
|
||||
{
|
||||
// user input for name
|
||||
cout << "Enter the name of student " << i+1 << ": ";
|
||||
getline(cin, name[i]);
|
||||
cin.clear();
|
||||
}
|
||||
//for loop to display names in ascending order
|
||||
bubbleSortNamesAscending(name, arr_size);
|
||||
for (int i = 0; i < arr_size; i++)
|
||||
{
|
||||
cout << name[i] << " ";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user