Answer to Question #322603 in C++ for kiki

Question #322603

. 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.

 



1
Expert's answer
2022-04-02T12:08:16-0400
#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');
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS