Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.
please put comment with code! and please do not just copy other solutions.
1. write the code using function
2. Please try to implement a function after the main function and provide prototype before main function.
Here is code:
#include <iostream>
#include <string>
using namespace std;
/*
countOccurrences return integer that number of times the key repeated in str array
*/
int countOccurrences(string *strs, int size, char key)
{
int count = 0;
// loop size times
for (int i = 0; i < size; i++)
{
// loop each string of item and count occurrence of char
for (int j = 0; j < strs[i].length(); j++)
{
if (strs[i][j] == key)
{
count++;
}
}
}
return count;
}
int main()
{
const int size = 5; // size of items
string str[size];
char c;
int count = 0;
// read string input from user
cout << "Enter five items." << endl;
for (int i = 0; i < size; i++)
{
cout << "Item " << i + 1 << ": ";
getline(cin, str[i]);
}
// read target char
cout << "\nTarget: ";
cin >> c;
// get the count of number of times occurence of 'c' in str array
count = countOccurrences(str, size, c);
cout << "The char " << c << " was found " << count << " times." << endl;
} // End of main()
Output:
Write a C++ program for the instructions below. Please read the instructions carefully and make sure...
Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to enter an item’s name for each position in the array. The program then prints uses a loop to output the array. Example 1: Banana 2: Orange 3: Milk 4: Carrot 5: Chips Banana, Orange, Milk, Carrot, Chips Problem 2: Print Characters in String Array Declare a string array of size 5. Prompt the user enters five strings that are stored in the array....
IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...
Write a C++ program for the instructions below. Please
read the instructions carefully and make sure they are followed
correctly.
please put comment with code! and please do not just
copy other solutions.
Instructions 1. Read instructions carefully! 2. Use C++ syntax only, C syntax will not be accepted. 3. Always use braces to define blocks. 4. Indent all lines within a block. Each block requires one more tab. 5. Organize your code well with proper formatting and a single...
This program should be run on Visual Studio. Please use printf
and scanf as input and output. Thank you
6.12 Lab Exercise Ch.6b: C-string functions Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs You will write 2 functions which resemble functions in the cstring library. But they will be your own versions 1. int cstrcat(char dstDchar src) which concatenates the char array srcl to char array dstD, and returns the...
1. You are given a C file which contains a partially completed
program. Follow the instructions contained in comments and complete
the required functions. You will be rewriting four functions from
HW03 (initializeStrings, printStrings, encryptStrings,
decryptStrings) using only pointer operations instead of using
array operations. In addition to this, you will be writing two new
functions (printReversedString, isValidPassword). You should not be
using any array operations in any of functions for this assignment.
You may use only the strlen() function...
Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. //...
C++
code please asap
QUESTIONS Write the test main function as described next. This function is NOT a member function of either of the two classes above. It is located in separate source file. Create an array of type Flight and size 10 1. Prompt the user to enter values for speed, name, and id for all 10 objects. You must use the overloaded input stream operator of class Flight. 1. Write the value of the name variable of all...
MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...
C programming 1 String Merging Write a program that reads two strings s1 and s2 from the keyboard and merges them to a string s3. Strings s1 and s2 are statically allocated whereas s3 is dynamically allocated to fit exactly s1 and s2. The two original strings are no longer than 100 characters long. Use the following function to merge the two strings. char *stringMerge(char s1[], char s2 []); Example: Enter the first string: Hello world Enter the first string:...
C++ Demonstrate an understanding of array processing. Write a function that accepts the name of a file (by asking the user), an array of strings, and the size of the array. Display each character of each string vertically to the file. For example, if the array is called with an array of 3 strings “hello”, “abc”, “bye”, the output will be: h e l l o …. y e Test the function with a string declaration of: string name[] =...