Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that creates a vector of N random ASCIII characters (note th

ID: 3816455 • Letter: W

Question

Write a C++ program that creates a vector of N random ASCIII characters (note the corresponding equivalent ASCIII code integers range from 26 to132), and then the sorts the random characters into alphabetical order and also in reverse alphabetical order Your code should create a random number vector with a minimum of 26 and maximum of 132, then convert the random numbers to random characters, then put the random number vector into rising/falling order, then finally convert the rising/falling numerical order to alphabetical and reversed and alphabetical order Note this will required double for loops in your program.

Explanation / Answer

c++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
   cout << "Enter the Value of N ";
   int N;
   cin >> N;
   std::vector<int> list;
   for (int i = 0; i < N; ++i)
   {
       int r = 26 + rand()%107;
       list.push_back(r);
   }
   cout << "Before Sorting" << endl;
   for (int i = 0; i < N; ++i)
   {
       cout << char(list[i]) << " ";
   }
   sort(list.begin(),list.end());
   cout << " After Sorting" << endl;
   for (int i = 0; i < N; ++i)
   {
       cout << char(list[i]) << " ";
   }
   cout << " Reverse Sorted" << endl;
   for (int i = N-1; i >= 0; --i)
   {
       cout << char(list[i]) << " ";
   }
return 0;
}

Sample output:

Enter the Value of N
5
Before Sorting
C Y / a *
After Sorting
* / C Y a
Reverse Sorted
a Y C / *
C:UsersAkashDesktopchegg>a
Enter the Value of N
10
Before Sorting
C Y / a * Ç 7 B â ^
After Sorting
* / 7 B C Y ^ a Ç â
Reverse Sorted
â Ç a ^ Y C B 7 / *

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote