?
Solved

a C++ program (arrays and pointers)

Posted on 2007-07-22
6
Medium Priority
?
309 Views
Last Modified: 2010-04-01
Hi all,
       I have this program to write in C++ and I have no idea how I should do it. Here is the details:
             I have to write a C++ program that allows the user to enter 100 integer data values to fill up an array, and then does the following. Introduce three pointers(to int) p, q and r. Set p and r to point to the first entry in the array. Set q to point just beyond the last entry in the array. Without introducing any integer variables, set up a loop in which p is incremented until it also points just beyond the end of the array. Also (inside the loop), whenever p points to a number that is bigger than the number r points to, then change r so that it also points to the same number p points to.
0
Comment
Question by:siddhuoops
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Anthony2000 earned 2000 total points
ID: 19544537
Would it help if I give you a rough outline of what you need to do and then you write the c++ code. Is this a homework assignment?

break the problem into small chunks

prompt a user to enter an integer  (cout << "Please enter an integer: ";)

repeat the above step 100 times

if the array in called user_integers, then
p = r = &user_integers[0]; // point to first element in the array

q = &user_integers[100];

loop using p, test p < q, increment p

if *p > *r then r = p

That about does it. Can you now complete the details...

0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 19544544
jkr,

Was I wrong to help the way I did???
0
 

Author Comment

by:siddhuoops
ID: 19545141
thank you both anthony2000 and jkr for guiding me to the right direction...yeah its a homework assignment and its a part of my project...i am completely aware of the fact that I am here for the guidance not to get a full solution..I should have mentioned that in my question...but the idea that you provided anthony2000 will definitely help me in completing my tasks...I will take that as a guideline and start working in it...thank you
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 19545445
If you have some code ready, then don't hesitate to post it here, and we can have a look at it to help you further in case that's needed.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question