Question
Question 1)Implement this instruction to the code provided. a) Create index_of which will return the index of a given name in the array. This should
Question 1)Implement this instruction to the code provided.
a) Create index_of 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)
Hint: Use similar logic to contains was found. from the video, but return the index where the name
b) Create a print_summary procedure that accepts the array and its size, then prints out all of the names, the total length of these names, the index of your name (or -1 if your name is not in the array), and the shortest name.
void print_summary(string data[ ] , int size)
c) Have create and work with an array of strings-
Use a constant for the size (make it 5)
Loop to read in the names
Call to output the details
Hint- No iostream please
Written Code-
#include"splashkit.h"
string read_string(string prompt)
{
string result;
write(prompt) ;
result = read_line();
return result;
}
int read_integer(string prompt )
{
string line;
line = read_string(prompt);
return convert_to_integer(line);
}
int total_length (string names[], int size)
{
int result = 0;
for(int i = 0; i , size, i++)
{
string name = names[i];
result += name.length();
}
return result;
}
void print_summary( string data[], int size)
{
int size;
string line;
}
int main()
{
#define SIZE 3
string names(SIZE);
int i;
i = 0;
while( i
{
names[i] = read_string("Enter a name: ");
i++;
}
for(i = 0; i
{
write_line(names[i]);
}
int total;
total = total_length(names, SIZE);
write_line("Total length: ");
write_line(total);
return 0;
}
deselashkit.h strirg read striegistring preapt) string result rite(pronpt) 1 result = read-line(); return result 3 int read integer string pronpt 14 string ire line read stringipreapt) return convert to integerrine): 21 int totsl length Istring nanesI), int size] int result 8; string nere naeIil result nane. LengthO return result 3 vold print sunnary string datel, int size) int 512e; string Lire; 40 int nainl) rdetine SIZE 3 string nones(SIZE i-0; aes[i- read string["Enter nare: write irea) int totaL total total_length(noves, s12E); write_linel Total lengths urite lineltotall: return 8 deselashkit.h strirg read striegistring preapt) string result rite(pronpt) 1 result = read-line(); return result 3 int read integer string pronpt 14 string ire line read stringipreapt) return convert to integerrine): 21 int totsl length Istring nanesI), int size] int result 8; string nere naeIil result nane. LengthO return result 3 vold print sunnary string datel, int size) int 512e; string Lire; 40 int nainl) rdetine SIZE 3 string nones(SIZE i-0; aes[i- read string["Enter nare: write irea) int totaL total total_length(noves, s12E); write_linel Total lengths urite lineltotall: return 8Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started