Need help with these, especially number 4. C++ program
#include <iostream>
using namespace std;
void mpgcalulator (double*, double*, double*);
#ifndef SIZE
#define SIZE 5
#endif
int main(int argc, char const *argv[])
{
double miles[SIZE], gallons[SIZE], mpg[SIZE];
for (int i = 0; i < SIZE; i++) {
cout << (i+1) << "."
<< endl;
cout << "miles coverd:
";
cin >> miles[i];
cout << "gallons consumed:
";
cin >> gallons[i];
}
mpgcalulator(miles, gallons, mpg);
for (int i = 0; i < SIZE; i++) {
cout << (i+1) << "."
<< endl;
cout << "miles coverd:
";
cout << miles[i] <<
endl;
cout << "gallons consumed:
";
cout << gallons[i] <<
endl;
cout << "mpg calcualted:
";
cout << mpg[i] <<
endl;
}
return 0;
}
void mpgcalulator (double *miles, double *gallons, double *mpg)
{
for (int i = 0; i < SIZE; i++)
mpg[i] = miles[i]/gallons[i];
}
/*******************************************************************************************
NOTE
COMPILATION:
1
g++ <file name>
default size of arrays are 5
2
g++ -D SIZE=10 <file name>
size of array would be 10
PROTOTYPE:
g++ -D SIZE=<required array
size> <file name>
*****************************************************************************************/
Need help with these, especially number 4. C++ program L. WIite the function Write a function...
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder program so that you can see how it is written using array notation. Your assignment is to convert the code to a program that uses only pointers and pointer math. Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section, no arrays of pointers and...
Make a program that will calculate and compute for the quotient of miles and gallons (mpg: miles per gallons). Your program should must ask the user to specify the size of the array (using dynamic array) for the following variable: miles ,gallons and mpg. Prompt the user to Initialize the value of miles (value for miles should be 100-250) and gallons (values should be from 5-25). Use pointer galPtr for gallons, milPtr for miles and mpgPtr for mpg. Use function...
- Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...
C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....
In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...
In C: Write a function "MinMax" that takes as an argument an integer array, an integer for the size of the array, and two integer pointers. The function should print nothing and return nothing but change the value of the first pointer to the minimum value in the array and change the value in the second pointer to the max value in the array.
write the program in c++ Pointen & A???ys: Write u function that is passed a pointer to a float array, and the size the array as an int. The function should return a pointer to the maximum element in the array The function should be: int *maxp(float* ap, int size) Write a main() program to lest the function with different input arrays. Grading Criteria (1 point each): Uses cin/cout correct function definition prompts user for input, reads it in correct...
I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...
Write a C program (not C++) that calls a function to multiply a matrix (two dimensional array). The main program should ask the user to enter an integer that will be used as the matrix “adder” and then call the function. The function should perform a matrix increment (every element of the array is incremented by the same value) and assign the result to another array. The function should be flexible enough to work with any array size and “adder”,...