Answer:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
// array fill and returnig array to the main()
float *arrayFill(float *arr) {
// srand() allows generate new random value everytime the program runs
srand(time(NULL));
for (int i = 0; i < 10; i++)
{
// array fill with random number between 0 to 100
arr[i] = (rand() % 100);
}
return arr;
}
// print array
void print(float* arr) {
cout << "Array: ";
for (int i = 0; i < 10; i++)
{
cout << arr[i] << " ";
}
}
float maxNum(float* arr) {
float temp = arr[0];
for (int i = 1; i < 10; i++) {
if (temp < arr[i]) {
temp = arr[i];
}
}
return temp;
}
int main() {
// creating dynamic array of elements 10 in heap memory
float *arrPtr = new float[10];
float result = 0;
// calling arrayFill()
arrPtr = arrayFill(arrPtr);
// calling print() to print array
print(arrPtr);
// calling maxNum() to find maximum number in the array
result = maxNum(arrPtr);
cout << "\nmaximum number: " << result;
delete[] arrPtr;
return 0;
}
Explanation:
please read inline comments inside the code section:)
Answer:
#include <iostream>
#include<string.h>
using namespace std;
void printCharacter(string name){
for(int i=0;name[i]!='\0';i++){
cout<<name[i]<<endl;
}
}
int main()
{
string name;
cout<<"enter the name: ";
cin>>name;
printCharacter(name);
}
Explanation:
first include the two libraries iostream for input/output and string library for using the string.
then, create the main function and declare the variable type string.
cout instruction is used o display the message on the screen.
cin is used to store the value in the name variable.
after that, call the function. The program control move to the the function. In the function for loop is used to print the character one by one until end of the name.
Answer:
The output is "Pasta"
Explanation:
Given
The attached code segment
Required
The output
The first line of the program implies that:
MyFavFood="Pasta"
This means that, the value of the variable MyFavFood is string "Pasta"
Next,
print (MyFavFood)
This prints the value of the variable MyFavFood which is "Pasta"
<em>Hence, the output is "Pasta"</em>
Answer:
Tell her to hold the Shift key as she hits Enter.
Answer:
zeroIt(&x);
Explanation:
The statement that sets the value stored in x to zero by invoking the function zerolt is given below
zeroIt(&x);
The zeroIt function is also given below for better understanding.
void zeroIt(int *x) {
*x = 0;
}
As seen, the function takes an argument with integer variable type, which is a pointer, denoted by the asterisk symbol (*x).
The ampersan sign (&x) is used to access the variable whose value can then be stored.