Question

In: Computer Science

Instructions Write a program in C++ that create a LookupNames project. In the main function: Ask...

Instructions

Write a program in C++ that create a LookupNames project.

In the main function:
Ask the user to enter a number of names, X to quit input.
Store the names in an array.
Also use a counter variable to count the number of names entered.

Write a function displayNames to display the names.
The function must receive the array and the counter as parameters.

Write a function called lookupNames.
The function must receive the array and the counter as parameters.
Ask the user to enter a letter.
Display all the names with the letter that was entered as the first letter of the name.

Call the displayNames and lookupNames functions from the main function.


Tip: declare your functions above the main() function:

void displayNames(char array[][60], int count)
{
// function code here
}

int main()
{
// main code here
displayNames(names, number);
// possible more code here
}

Tip2: make sure your function parameter matches the data type you send as an argument to that function.
In the above example, names and array should have the same data type, and number and count should have the same data type.


Enter name (X to quit input): John Peterson
Enter name (X to quit input): Diane Lee
Enter name (X to quit input): James Smith
Enter name (X to quit input): Frank Xaba
Enter name (X to quit input): Jacky Mokabe
Enter name (X to quit input): x


List of Names

John Peterson
Diane Lee
James Smith
Frank Xaba
Jacky Mokabe

Enter a letter: J

Names starting with the letter J

John Peterson
James Smith
Jacky Mokabe

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<iostream>
#include<cstring>
using namespace std;


void displayNames(char array[][60], int count){
  
   cout<<"List of Names\n";
   for(int i=0; i<count;i++){
       cout<<array[i]<<endl;
   }
   cout<<endl;

}

void lookupNames(char array[][60], int count){
   char letter;
   cout<<"Enter a letter: "; cin >> letter;
   for(int i=0; i<count;i++){
       if(array[i][0]==letter)
       cout<<array[i]<<endl;
   }
}

int main(){
  
   const int SIZE = 100;
   char names[SIZE][60];
   char name[60];
   int count = 0;
  
   while(count<SIZE)   {
       cout<<"Enter name (X to quit input): ";
       cin.getline(name,59,'\n');
       if(strcmp(name,"X")==0 || strcmp(name,"x")==0) break;
      
       strcpy(names[count],name);
       count++;
   }
  
   displayNames(names, count);
  
   lookupNames(names, count);

   return 0;
}

=================================================================


Related Solutions

Create a C++ project called RobberyLanguage. Ask the user to enter a word. Write a function...
Create a C++ project called RobberyLanguage. Ask the user to enter a word. Write a function that will receive the word, use the word to compile a new word in Robbery language and return the new Robbery language word. In the function: Use a while loop and a newline character (‘\0’) to step through the characters in the original string. How to compile a word in Robbery language: Double each consonant and put the letter ‘o’ between the two consonants....
Write a C++ program which consists of several functions besides the main() function. The main() function,...
Write a C++ program which consists of several functions besides the main() function. The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. A value-returning function called Power(int a, int b) that...
C++ Write a program that has two functions. The 1st function is the main function. The...
C++ Write a program that has two functions. The 1st function is the main function. The main function should prompt the user for three inputs: number 1, number 2, and an operator. The main function should call a 2nd function called calculate. The 2nd function should offer the choices of calculating addition, subtraction, multiplication, and division. Use a switch statement to evaluate the operator, then choose the appropriate calculation and return the result to the main function.
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
********************C# C# C#******************** Part A: Create a project with a Program class and write the following...
********************C# C# C#******************** Part A: Create a project with a Program class and write the following two methods(headers provided) as described below: 1. A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number if the number is not in the range...
Create a shell in C language 1) Create an argument tokenizer then write a main() function...
Create a shell in C language 1) Create an argument tokenizer then write a main() function that prints a prompt inputed by user, accepts input, and tokenizes the input. 2) Use the argument vector to an executeCmd() function with int executeCmd(char **args); 3) The function should return a -1 if an error, or a zero otherwise. Inputing an “x” in the prompter will exit the program. 4) Write an executeCmd() function that can execute any program in the background and...
Write a complete C++ program that at least consists of the main() function and at least...
Write a complete C++ program that at least consists of the main() function and at least two recursive functions. The first function has no return value and can be named printPrime(). It prints first n prime numbers with proper prompt. Note that number 1 is not regarded as a prime number. We assume the first prime number is 2. The printout should start from 2. The prototype of the recursive function should be void printPrime(int n); The algorithm of printPrime()...
Create a new project called Lab05b. Keep the main file named main. Write a function readAndPrint,...
Create a new project called Lab05b. Keep the main file named main. Write a function readAndPrint, and power with parameters noted below in the Functions.h file. //Your Last Name #ifndef FUNCTIONS_H #define FUNCTIONS_H #include <fstream> #include <iostream> #include <string> using namespace std; /*reads from a file and prints every item to the screen*/ // file contains sets of //int //string //Don't forget to use infile.ignore() between << and getline //ifstream must be passed by reference void readAndPrint(ifstream &infile); //uses a...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the computer user to enter his/her: • Name: a string representing the user’s first name • month of birthday: an integer representing the month of the user’s birthday • day of birthday: an integer representing the day of the user’s birthday • year of birthday: an integer representing the year of the user’s birthday Consider the following aspects that your program shall perform: VALIDATE USER’S...
write a program in C language Create a function to perform the insertion sort. Now the...
write a program in C language Create a function to perform the insertion sort. Now the program will perform the following steps: Prompt the user to enter the number of array elements (say, N). Read the number of elements (N). Use dynamic memory allocation to allocate an array of N single precision floating-point elements (C type float). Read the N single precision floating-points elements to the allocated array. Invoke a function to sort the array using insertion sort (the insertion...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT