Question: #include splashkit.h #define SIZE 5 string read_string(string prompt) { string result; write(prompt); result = read_line(); return result; } int read_integer(string prompt) { string line; int

#include "splashkit.h"

#define SIZE 5

string read_string(string prompt)

{

string result;

write(prompt);

result = read_line();

return result;

}

int read_integer(string prompt)

{

string line;

int result;

line = read_string(prompt);

result = convert_to_integer(line);

return result;

}

int index_of(string value, string data[], int size)

{

for(int i=0; i

{

if(data[i]==value)

return i;

}

return -1;

}

void print_summary(string data[], int size){

for(int i=0; i

write(data[i]);

}

}

bool contains(string names[], int size, string name)

{

for(int i = 0; i < size; i++)

{

if(to_lowercase(names[i]) == to_lowercase(name))

{

return true;

}

else

{

return false;

}

}

return false;

}

string shortest_name(string names[], int size)

{

string min;

min = names[0];

for(int i = 1; i < size; i++)

{

if( min.length() > names[i].length())

{

min = names[i];

}

}

return min;

}

int main()

{

#define SIZE 5

string names[SIZE];

int i;

i=0;

while ( i < SIZE )

{

names[i] = read_string("Enter a name: ");

i++;

}

for(i = 0; i < SIZE; i++)

{

write_line(names[i]);

}

int total;

total = (names, SIZE);

write("Total length: ");

write_line(total);

bool has_frank;

has_frank = contains(names, SIZE, "frank");

if (has_frank) write_line("Contains Frank");

write_line(shortest_name(names, SIZE));

return 0;

}

//Create an index_of function which will return the index of a given name in the array. This should return -1 if the name is not present. int index_of(string value, string data[], int size)

For example: if we have an array of names - [ "VIcas", "Random,", "Frank", "James", "Dollar" ] - and we are searching for the name "Frank", then calling the contains function should return true (Frank is in the array) and calling the index_of function should return 2 (Frank is at index 2 in the array).

Create a print_summary procedure that accepts the array and its size passed into it as parameters, then prints out all of the names in the array, the total length of these names (the length of all of the names added together), the index_of your name (or -1 if your name is not in the array), and the shortest name. Use this for the first line of your procedure: void print_summary(string data[], int size)

Modify the main function to declare and work with an array of strings:

  • Use a constant for the size (make it a size of 5)
  • Call print summary to output the details

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!