Help please! Who can do this program?

P

phil goddard

This homework tests your understanding of pointers and how to use
pointers with arrays and functions.
What we want to do is find the next highest int in an array based on a
given float, i.e. in the following example, based on the float 7.11 we
want to find the 8.

Tasks:
1) Include all the required libraries and define a main().
2) In main, define a
a. float called myFloat, initialize it with 7.11
b. one dimensional array called testArray[10]={1,2,3,4,5,6,7,8,9,10};
c. an int called testArraySize=10
d. call the function like so:

3) Define two pointers fPtr and aPtr and initialize them to point to
the float and the array
4) Define another pointer called resultPtr, type int*, initialize it
to NULL
5) In main, call the function foo() like so:
resultPtr = foo(fPtr, aPtr, testArraySize);
6) Define a function foo() that
a. receives a) a pointer to a float – myFloatPtr and b) a pointer to
an integer myIntPtr and c) an integer myInt,
b. and returns a pointer to an integer
c. Using the pointer notation (i.e. NOT the [subscript] notation !!!),
i. Use the myIntPtr, which points to the beginnigng of testArray (i.e.
the 1) , and loop through the array until either the content of what
myFloatPtr is pointing to (myFloat) is no longer less than the content
of what myIntPtr is pointing to(condition 1), or until a counter
(initialized with 0) is no longer less than myInt (the size of the
array that was passed down – that makes sure you don't keep going past
the array size) (condition 2).
ii. While doing the comparison, you will need to cast the content of
the myFloatPtr to an int to avoid warnings.
iii. When condition 1 is met, return the content of myIntPtr, (the
address of where the number in the array that was larger than the
float is located, NOT what myIntPtr is pointing to!)
iv. Else if condition 2 is met, return NULL.
7) Back in main, test if the returned resultPtr is NULL, if yes,
display "NOT FOUND", if not, display the content of what the pointer
is pointing to, which should be 8.
 
A

Aggro

phil said:
This homework tests your understanding of pointers and how to use
pointers with arrays and functions.
What we want to do is find the next highest int in an array based on a
given float, i.e. in the following example, based on the float 7.11 we
want to find the 8.

Many of us can do it, but it is your homework, so you should do it. So
what are you waiting for? You got the specs, start coding.
 
C

Christopher Benson-Manica

phil goddard said:
This homework tests your understanding of pointers and how to use
pointers with arrays and functions.

It also tests your personal integrity - if you post to a newsgroup
expecting other people to do your work for you, then you fail. I hear
Enron is looking for people just like you.
 
M

Mark A. Gibbs

my god. are all cs homework assigments this specific? we sure as hell
didn't get it that easy in engineering. this isn't typical, is it?

mark
 
R

rossum

This homework tests your understanding of pointers and how to use
pointers with arrays and functions.
What we want to do is find the next highest int in an array based on a
given float, i.e. in the following example, based on the float 7.11 we
want to find the 8.
[snip]

In answer to your question, yes I can do this program. Depending on
precisely what it is that you want me to do, my rates go up to GBP 200
per hour.

rossum
 
M

Mike Wahler

Re: Help please! Who can do this program?

I can do it.

Next question?

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top