Hey guys I'm a beginner in c++ i really need ur help with this program. thx
in advance(i need all ur suggestions i only have few hours in order to present it)
1. Write a function "total" that takes one pointer to integer and one integer as arguments.
a. Assume that when function total is invoked it will receive an integer array along with its size from the caller. The function total should calculate and return the total of the integers in the array. When accessing the elements in the array use pointer+offset notation not square brackets.
b. The function total should also return whether any of the numbers in the array sent to it are greater than 100 (recall how to return more than one value from a function). When coding this part (b) of the function, use square bracket notation to access the elements.
c. Call the function total sending to it 10 integer values (an array of integers named iArray1 which contains randomly generated numbers between 50 and 150).
d. Create a pointer to integer named iptr and make it point to array iArray1.
e. Print each integer of iArray1 on a separate line
f. Call the function total once more, this time sending iptr rather than iArray1.
g. Create a 4x6 2-dimensional integer array
h. Call the total function in a loop FOR EACH row of the 2 dimensional array and display the results
2.
a. Create a pointer to character named cptr which will point to the string “hello”. Print the string.
b. Change each character of the “hello” you created in part f to its ASCII value and store each value in an integer array named iArray2.
c. Print each character of cptr on a separate line
d. Create a pointer to character named cptr2 and make it point to the last character of the string “hello” which you created in part f.
e. Call 2 of the built in functions from the string handling library seen in class and demonstrate their functionalities. Display the results.
I don't blame you for asking help. This assignment is retarded, in particular point b).
So here's part of the solution, written in C. You may... might easily convert it to C++.
(Presumably, you do not even know the difference between the two. But I guess neither your instructors.)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int total(int *pi, int size)
{
int r=0;
while (size--)
r += *pi++;
return r;
}
int main(void)
{
int iArray[10];
int i;
srand(time(NULL));
for (i=0; i < sizeof iArray / sizeof *iArray; ++i)
iArray[i] = rand() % 100 + 50;
printf("The iArray contains:\n");
for (i=0; i < sizeof iArray / sizeof *iArray; ++i)
printf("%d\n", iArray[i]);
printf("Total of its elements is: %d.\n", total(iArray, sizeof iArray / sizeof *iArray));
system("PAUSE");
return EXIT_SUCCESS;
}
Hey guys I'm a beginner in c++ i really need ur help with this program. thx
in advance(i need all ur suggestions i only have few hours in order to present it)
I'm reluctant to help because it sounds like a school project. You're not going to learn much from getting a full coded example from someone online. You'll not understand it and you'll only been cheating yourself. In that sense, it is a complete waste of time for both you and I.
That isn't to say that I'm against helping people who have school projects. I'm more than happy to give a nudge in the right direction for specific problems. Yours, however, is far from specific and sounds like you're just looking for a solution to help you scrape by.
As chipp pointed out, we get this a lot on these boards. And my response is the same as it always is; try it yourself first and shout up when you get stuck.
@iHutch105 well...if i needed someone to advice me and talk shit i would have asked for that dude!
As for
@Carfish2 thanks for ur help and interest, I'm gonna take the logic and do it for a c++ forum since it's a c++ assignment and I'm gonan post it back for further hep and correction if any ;)