C++ programming {{{please i need all codes and it should creat class ,hedear fil
ID: 3574326 • Letter: C
Question
C++ programming
{{{please i need all codes and it should creat class ,hedear file ,and cpp file}}}
please the output should be same the output in this question as following:
Q:
Implement a program that sort numbers or characters.
1. The program should sort the input from the user. the input can be numbers(integer or float type) or characters (char type).
2. in main function, you only get the input value. make additional sort function and print function for the program.
3. the order of same number or character is not considered.
4. this is the example of program results.
Data items in original order
> 6 4 8 10 12 89 68 45 37
Data items in ascending order
> 4 6 8 10 12 37 45 68 89
Data items in original order
> 5.2 36.5 3.4 12.8 1.9 6.8 24.3
Data items in ascending order
> 1.9 3.4 5.2 6.8 12.8 24.3 36.5
Data items in original order
> I n h a U n i v .
Explanation / Answer
................................................
sorting_num_and_char.h
..................................................
void sort_integers(int arr[], int size);
void print_sorted_integers(int arr_int[],int s);
void sort_float(float arr[], int size);
void print_sorted_float(float arr_float[],int s);
void sort_characters(char arr[], int size);
void print_sorted_character(char arr_char[],int s);
int main();
.....................................................
sorting_num_and_char.cpp
....................................................
#include <iostream>
#include "sorting_num_and_char.h"
using namespace std;
void sort_integers(int arr[], int size)
{
int i,j;
cout << "Sorting the integers are' << endl;
int arr1[size];
for (i=0;i<size-1;i++)
{
for(j=0;j<size-i-1;j++)
if(arr[j]>arr[j+1])
{
int t=arr[j];
arr[j]=arr[j+1];
arr[J+1]=t;
}
arr1[j]=arr[j];
}
print_sorted_integers(arr1,size);
}
void print_sorted_integers(int arr_int[],int s)
{
int i;
cout << "Sorted integers are' << endl;
for(i=0;i<s-1;i++)
{
cout << arr_int[i] << "," ;
}
}
void sort_float(float arr[], int size)
{
int i,j;
cout << "Sorting float numbers are' << endl;
float arr2[size];
for (i=0;i<size-1;i++)
{
for(j=0;j<size-i-1;j++)
if(arr[j]>arr[j+1])
{
float t=arr[j];
arr[j]=arr[j+1];
arr[J+1]=t;
}
arr2[j]=arr[j];
}
print_sorted_float(arr2,size);
}
void print_sorted_float(float arr_float[],int s)
{
int i;
cout << "Sorted float numbers are' << endl;
for(i=0;i<s-1;i++)
{
cout << arr_float[i] << "," ;
}
}
void sort_characters(char arr[], int size)
{
int i,j;
cout << "Sorting the characters are' << endl;
char arr3[size];
int asci_char[size];
for(i=0;i<size-1;i++)
{
asci_char[i]=arr[i]; // converting the alphabets into ascii numbers and sorting according them
}
for (i=0;i<size-1;i++)
{
for(j=0;j<size-i-1;j++)
if(asci_char[j]>asci_char[j+1])
{
char t=arr[j];
arr[j]=arr[j+1];
arr[J+1]=t;
}
arr3[j]=arr[j];
}
print_sorted_character(arr3,size);
}
void print_sorted_character(char arr_char[],int s)
{
int i;
cout << "Sorted characters are' << endl;
for(i=0;i<s-1;i++)
{
cout << arr_char[i] << "," ;
}
}
int main()
{
int in, fl, ch;
cout << " The integers you want to sort is :-" << endl;
cin >> in;
cout << " The float numbers you want to sort is :-" << endl;
cin >> fl;
cout << " the characters you want to sort is :-" << endl;
cin >> ch;
cout << " Enter your " << in << "integers you want to sort :-" << endl;
int arr_in[in];
for (int i:arr_in)
cin >> i;
sort_integers(arr_in,in);
cout << " Enter your " << fl << "float numbers you want to sort :-" << endl;
float arr_fl[in];
for (float f:arr_fl)
cin >> f;
sort_float(arr_fl,fl);
cout << " Enter your " << ch << "characters you want to sort :-" << endl;
char arr_ch[in];
for (char c:arr_ch)
cin >> c;
sort_characters(arr_ch,ch);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.