Question

In: Computer Science

Create and initialize a string array, write and use 3 functions.Write a program. Create a string...

Create and initialize a string array, write and use 3 functions.Write a program.

Create a string array in the main(),called firstNameArray, initialize with7 first namesJim, Tuyet, Ann, Roberto, Crystal, Valla, Mathilda

Write a first function, named searchArray, that passes two arguments: a single person’s name and the array reference, into a function,This function should then search the array to see if the name is in the firstNameArray. If found, it will return the array index where the name is found, else it return the number 7.(This function needs 3 parameters –see code examples above)

Write the code in the main program to call/use the searchArray function. Check the return value for the index value returned. Print the name using the index number(0 to 6), or prints ‘name not found’ if it return a 7.

Write a second function, print AllNames, that will print all the names in the array.Pass the array into the function. (This function needs two parameters –see code example above)

Write the code in the main program to call/use this printAllNames function.

Write a third function, called deleteName, that will delete a name from the array. Check first to see if the name is in the array, before you try to delete it(use the searchArray function).If you find the name, then write “ “ to the location in the array. ... Just making spot blank.(This function requires 3 parameters –see code examples above).

Call the printAllNames function to print the array to verify you have deleted a value.Print out the array... if the spot/index in the array is blank do not print it.

C++

Solutions

Expert Solution

In case of any query do comment. Thanks

Note: Your question was stating about (This function needs 3 parameters –see code examples above) whihch you did not clarify, I assumed this must be length of the array, if you have any other parameter do let me know I will update answer.

Code:

#include <iostream>
using namespace std;

//function to search given name in firstNameArray, length is third parameter 
int searchArray(string name, string firstNameArray[], int length){
    
    for (int i = 0; i < length; i++) {
        if(firstNameArray[i] == name){
            return i;
        }
    }
    
    return 7;
}

//print all values in array
void printAllNames(string firstNameArray[], int length){
    
    for (int i = 0; i < length; i++) {
        if(!firstNameArray[i].empty())   //if empty name then don't print it
            cout << firstNameArray[i] <<endl;
    }
    
}

//function to delete name from aray by making it ""
void deleteName(string name, string firstNameArray[], int length){
    
    int index = searchArray(name,firstNameArray,length);
    
    if(index !=length){
        firstNameArray[index] ="";
    }
}

int main()
{
    //declare an array and initialized
    string firstNameArray[] = {"Jim", "Tuyet", "Ann", "Roberto", "Crystal", "Valla", "Mathilda"};
    int length=7;
    int index =-1;
    string name = "Jack"; //search for string jack which will return 7
    index = searchArray(name,firstNameArray,length);
    
    if(index == length){
        cout << name << " not found" <<endl;
    }  
    else
    {
        cout << firstNameArray[index]<<endl;
    }
    
    //display array names
    printAllNames(firstNameArray,length);
    //trying to delete Roberto
    deleteName("Roberto",firstNameArray,length);
    cout<< endl<< "After deleting Roberto" <<endl <<endl;
    printAllNames(firstNameArray,length);
    return 0;
}

==============Screen shot of the code for indentation=======

output:


Related Solutions

In C++, create a 3-by-3 array that is capable of storing integers and initialize each entry...
In C++, create a 3-by-3 array that is capable of storing integers and initialize each entry to 0. Ask the user to supply a row and a column and a value, then put the value into the array at that row and column. Print the array to the screen as a table with 3 rows and 3 columns, and ask the user for another row, column, and value. Repeat until user inputs values for all entries. Once finished, compute and...
Write a Java program to initialize an array with the even integers from 2 to 20...
Write a Java program to initialize an array with the even integers from 2 to 20 and print the result then pass this array to a method in order to create a new array which is the inverse of the array you passed (print the result). You cannot use a third array. Insert comments and version control in the program to document the program.
Write a recursive method to determine if a String is a palindrome. Create a String array...
Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. In Java
Write a PHP program that checks the elements of a string array named $Passwords. Use regular...
Write a PHP program that checks the elements of a string array named $Passwords. Use regular expressions to test whether each element is a strong password. For this exercise, a strong password must have at least one number, one lowercase letter, one uppercase letter, no spaces, and at least one character that is not a letter or number. (Hint: Use the [^0-9A-Za-z] character class.) The string should also be between 8 and 16 characters long. The $Passwords array should contain...
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and...
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and "multiplier", as user input. Create an array of integers with arraySize elements. Set each array element to the value i*multiplier, where i is the element's index. Next create two functions, called PrintForward() and PrintBackward(), that each accept two parameters: (a) the array to print, (b) the size of the array. The PrintForward() function should print each integer in the array, beginning with index 0....
Create a program that calculates the average of 3 test scores. Make use of an array...
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores. const int size = 3; int testScores[size]; Send this array to a function that actually calculates and returns the average. 1. Tell the user what the program does. 2. Prompt the user to enter the integer scores. ( Use a for loop to do this. ) 3. Create and implement a function with prototype: double average( int a[], int...
Sort a string array by frequency given an array of string write a function that will...
Sort a string array by frequency given an array of string write a function that will return an array that is sorted by frequency example {"hello","hola","hello","hello","ciao","hola","hola","hola"} returned array should be {"hola","hello","ciao"}
Create a complete java program called Week_Report. The program must include two array structures, a string...
Create a complete java program called Week_Report. The program must include two array structures, a string array called DaysOfWeek and a double array called Temp_Values. Store in the DaysOfWeek array the following values (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday). Store in the Temp_Values array the following (23.5, 34.0, 20.9, 45.7, 29.3, 34.5, 32.5). Using a for loop structure output the values for the two arrays. Day of the Week Temperature Values Monday 23.5 Tuesday 34.0 Wednesday 20.9 Thursday 45.7...
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting from 1. Your element [0][0] should be equal to 1; element[4][4] should be equal 25. Print the array. The output should have 5 rows and 5 columns. Specify the width for each output to demonstrate the table in a formatted view. Change the value of the elements: 2nd row 4th column to 24, 1st row 3rd column to 13. Print the array again. Find...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT