64 624
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #9164 in C++ for samah

Question #9164
Exercise 1 – Arrays
Write a C++ program that asks the user to enter a number n followed by n words. These words will be
stored in an array. The program will read the content of the array and make the following changes:
‐ The words that have 4 characters or less will be changed by the word invalid
‐ The words that have 5 characters or more will be transformed as follows: The first and the last
characters will remain the same. However, the other characters will be transformed into stars
(*)
The program will display at the end the new content of the array as well the percentage of words that
have been changed into the word invalid.
Expert's answer
#include <iostream>
#include <string>
using namespace std;

int main ()
{
int n;
string str;
cout << "Enter n: ";
cin >> n;
string *words = new string[n];
for (int i = 0; i < n; i++){
& cin >> str;
& if (str.size() <= 4){
& words[i] = "invalid";
& }
& else& {
& words[i] = str.replace(1,str.size()-1,"*");
& }
}

for (int i = 0; i < n; i++){
& cout << words[i] << endl;
}

system("pause");
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

muhammad ismail iqbal
08.03.13, 15:33

#include<stdio.h>
#include<conio.h>
main()
{
int array[100] , n , temp ;
int i , j ;
printf("Enter number of elements if you want to insert : ") ;
scanf("%d" , &n) ;
for(i=0 ; i<n ; i++)
{
printf("Enter elements" , i +1 ) ;
scanf("%d" , &array[i]) ;
}
for(i=0 ; i<n/2 ; i++)
{
temp = array[i] ;
array[i] = array[j] ;
array[j] = temp ;

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions