. Write a C++ program that reads 10 characters from user (user can type any character i.e., small or capital alphabets, digits, special characters). Convert all small alphabets to capital alphabets and capital alphabets to small alphabets. Store each type of character in separate arrays i.e., small alphabets in separate array, digits in separate array etc.
■ Provide a menu with the following options to the user,
Menu
Press 1 to Input the array
Press 2 to process the array [as per the requirements provided above]
Press 3 to print the capital letters
Press 4 to print the digits
Press 5 to print the special characters
■ Use the appropriate fundamental programming constructs i.e., variables, control-flow, loop, functions etc.
#include<iostream>
#include<vector>
using namespace std;
void Menu()
{
cout << "\nMenu\nPress 1 to Input the array"
<< "\nPress 2 to process the array[as per the requirements provided above]"
<< "\nPress 3 to print the capital letters"
<< "\nPress 4 to print the digits"
<< "\nPress 5 to print the special characters"
<< "\nPress 0 to exit";
cout << "\nPlease, make a select: ";
}
void InputArray(char s[])
{
cout << "\nPlease, enter 10 characters:";
for (int i = 0; i < 10; i++)
{
cin >> s[i];
}
}
void ProccessArray(char s[])
{
cout << "\nPlease, enter 10 characters:";
for (int i = 0; i < 10; i++)
{
cin >> s[i];
}
}
int main()
{
char c;
char str[10];
vector<char> sabets;
vector<char>cabets;
vector<char> dig;
vector<char> spec;
do
{
Menu();
cin >> c;
switch (c)
{
case '1':
{
InputArray(str);
break;
}
case '2':
{
for (int i = 0; i < 10; i++)
{
if (isalpha(str[i]))
{
if (isupper(str[i]))
{
str[i] = tolower(str[i]);
sabets.push_back(str[i]);
}
else if (islower(str[i]))
{
str[i] = toupper(str[i]);
cabets.push_back(str[i]);
}
}
else if (isdigit(str[i]))
{
dig.push_back(str[i]);
}
else
{
spec.push_back(str[i]);
}
}
cout << "\nProccess has been complted" << endl;
break;
}
case '3':
{
vector<char>::iterator it;
for (it = cabets.begin(); it != cabets.end(); it++)
{
cout << *it << " ";
}
break;
}
case '4':
{
vector<char>::iterator it;
for (it = dig.begin(); it != dig.end(); it++)
{
cout << *it << " ";
}
break;
}
case '5':
{
vector<char>::iterator it;
for (it = spec.begin(); it != spec.end(); it++)
{
cout << *it << " ";
}
break;
}
}
} while (c != '0');
}
Comments
Leave a comment