Answer to Question #264812 in C++ for Anas

Question #264812

Write a program which takes 10 strings from the user and saves it in the vector container. Then, using map - an associative container - process the vector, so that in the end, the map contains strings as keys and number of occurrences as a value.

1
Expert's answer
2021-11-12T00:54:56-0500
#include <iostream>
//#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
	//Declare Variables
	char string[10][30]; //2D array for storing strings
	int i, n;
	cout<<"Enter number of strings to input\n"<<endl;
	cin>>n;


	//Read the string from user
	cout<<"Enter Strings one by one: \n"<<endl;
	for(i=0; i< n ; i++) {
		cin>>string[i];
	}


	//Print the length of each string
	cout<<"The length of each string: \n"<<endl;
	for(i=0; i< n ; i++) {
		//Print the string at current index
		cout<<string[i]<<endl;


		//Print the length using `strlen` function
		cout<<strlen(string[i])<<endl;
	}


	//Return to the system
	return 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