Professional Documents
Culture Documents
}
Array of strings in C++ (cont.)
Print an array contains the names of a set of students and the number of characters in
#include<iostream>
each name. Also write and call function that print number of repletion of each name.
using namespace std;
void print_frequency(string names[], int n)
{ int main()
int frequency[n]; {
int visited =-1; int n;
for(int i = 0; i <n; i++) cout<<"Enter The number of students"<<endl;
{
cin>>n;
int count = 1;
for(int j = i+1; j < n; j++)
cin.ignore();
{ string names[n];
if(names[i] == names[j]) cout<<"Enter the names of students"<<endl;
{ for(int i=0; i<n;i++)
count++; {
frequency[j] = visited;
getline(cin,names[i]);
}
}
}
if(frequency[i] != visited) cout<<"Names\t\tLength"<<endl;
frequency[i] = count; cout<<"----------------------"<<endl;
} for (int i = 0; i< 5; i++)
cout<<"\n\nNames\t\tFrequency"<<endl; cout << names[i]<< "\t\t"<<names[i].length()<<endl;
cout<<"----------------------"<<endl;
for(int i = 0; i < n; i++)
{
print_frequency(names,n);
if(frequency[i] != visited) return 0;
cout<< names[i]<<"\t"<<frequency[i]<<endl; }
}
}
Any Questions?????