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[] = {"hello", "abc", "bye"};

#include <iostream>
#include <fstream>
using namespace std;
void writeToFile(string fname, string a[], int n)
{
ofstream mf; // declaring variables
mf.open (fname);
for(int i=0; i<n; i++) // looping for n times
{
for(int j=0; j<a[i].length(); j++) // taking each char
mf << a[i][j] << endl; // writing to file in a line
}
mf.close(); // closing
}
int main() {
// declaring variables
string fname;
int n;
string name[] = {"hello", "abc", "bye"};
cout << "Enter name of the file: ";
cin >> fname;
writeToFile(fname, name, 3);
}
/*OUTPUT
out.txt
h
e
l
l
o
a
b
c
b
y
e
*/
// Hit the thumbs up if you are fine with the answer. Happy Learning!
C++ Demonstrate an understanding of array processing. Write a function that accepts the name of a...
Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument is “hello. my name is Joe. what is your name?” the function should return the string “Hello. My name is Joe. What is your name?” The program should let the user enter a string and then pass it to the function. The modified string should be displayed.
(C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...
Write a value-returning C++ function returns the average length of an array of strings. Name the function stringsAverageLength and use the following header: double stringsAverageLength(string array [], int n) { } where the parameter 'array' has 'n' strings and the return value is the average length of all of the strings in the array. For example, if the function is called like this: string cars[3] = { "Toyota", "Ford", "Tesla" }; cout << fixed << setprecision(2) << stringsAverageLength(cars, 3) <<...
1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...
9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named...
write a C++ function that accepts a pointer to a C-string as an argument and displays its contents backward. For instance, if the string argument is “ Gravity ” the function should display “ ytivarG ”. Demonstrate the function in a program that asks the user to input a string and then passes it to the function.
C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and the size of the array.as parameters. The function should then create a new array that is the same size as the original array. The function should copy the elements from the first array into the second array in reverse order. So if the initial array is {'a' , 'b', 'c'} then the new array will be {'c', 'b', 'a'} Then in your main(), create...
1. Write a function to keep asking the user for names in the form of strings, sort alphabetically and store these names into a text file named names.txt 2. Write a function that accepts a string as the argument, removes all alphabetical letters from the string, and returns it 3. Write a function that accepts a file name in the form of a string as the argument. Assume the text file contains single-digit numbers and letters. Read the entire contents...
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.
Total Characters in String Array 10 points Problem 2 Declare a string array of size 5. Prompt the user enter five strings that are...
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....