I need to get this done before midnight tonight and I really need some help...Can someone show me how to code these problems? I have to show the rest of the class how to code it
1. Write a function that accepts a pointer to an array of integers and a single integer. Search the array for the integer and return a pointer to that element in the array. Do not use array notation.
2. Write a function that accepts an integer, prompts the user for that number of values, loads the values into an array (without using array notation) and returns a pointer to the array to the calling function.
3. Write a recursive function that excepts two integers, x and n, calculate x to the nth power and returns the result to the calling function.
Thanks,
Teacher in Training
8 1294
Can someone help me explain these problems? I'm trying to teach my little brother how to code these ...
Now its "you have to show the rest of the class", but it has to be done by midnight? hmm.
We are not here to do your home work for you so don't ask.
He's in the class that i'm doing my student teaching...the teacher just gave me these problems to see if i could work them out but I haven't taken C++ since high school
Now its "you have to show the rest of the class", but it has to be done by midnight? hmm.
We are not here to do your home work for you so don't ask.
Regardless of your intent, it is against our site policy to just give out code on demand. And I hate to sound impertinent, but if you are student teaching a programming class, shouldn't you know how to code?
i do, but i'm stuck.....can you help me figure this out?
Regardless of your intent, it is against our site policy to just give out code on demand. And I hate to sound impertinent, but if you are student teaching a programming class, shouldn't you know how to code?
If you are asking us to pity you, you get the exact opposite. I feel sorry for the students, who are going to learn from someone who has no clue what he is doing. Moreover, your approach was not "I need to learn" but "I need to somehow get my work done for me". Your attitude won't get you any respect on technical forums.
It's too much to hope that you'll use modern C++ idioms to answer the above three questions. Maybe you'll figure out the answer to them the C way. But I'll make some points anyway:
Q1: This question is deceiving. That function should not simply take in a pointer to an array and the integer to search. That is, either you should be using some sort of container for an array, like a vector, or you should be passing in the size of the array.
Also, I consider it bad design to pass around pointers unnecessarily. Passing pointers here is unnecessary. Well, if you pass in an array directly, it will decay to a pointer. Ideally though, you want the function to promise that the array won't be modified. Also, returning a pointer is a bad idea. You get no penalty for returning an integral index, but it makes ownership semantics much clearer. If you return a pointer, the big question is going to be, who manages that pointer?
Q2: A vector might be more appropriate in place of an array. Or if going the array route anyway, returning a raw pointer is problematic. Because now you have used new in one place, and must bet that delete will be called appropriately later on. Using a smart pointer like shared_array or whatever would be more appropriate here.
i'm just trying to freshen up on my skills... here's what i got so far on the first problem...its wrong but i tried...
int main()
{
int myArray [5]={22,23,34,45,12,}
int *myArray = new int [size];
for ( int i = 0; i<size; i++)
{
cout<<(myArray+ i);
}
return myArray;
this is the first one...they havent covered vectors and they didn't cover it in my former C++ class so i'm not sure what to do now
If you are asking us to pity you, you get the exact opposite. I feel sorry for the students, who are going to learn from someone who has no clue what he is doing. Moreover, your approach was not "I need to learn" but "I need to somehow get my work done for me". Your attitude won't get you any respect on technical forums.
It's too much to hope that you'll use modern C++ idioms to answer the above three questions. Maybe you'll figure out the answer to them the C way. But I'll make some points anyway:
Q1: This question is deceiving. That function should not simply take in a pointer to an array and the integer to search. That is, either you should be using some sort of container for an array, like a vector, or you should be passing in the size of the array.
Also, I consider it bad design to pass around pointers unnecessarily. Passing pointers here is unnecessary. Well, if you pass in an array directly, it will decay to a pointer. Ideally though, you want the function to promise that the array won't be modified. Also, returning a pointer is a bad idea. You get no penalty for returning an integral index, but it makes ownership semantics much clearer. If you return a pointer, the big question is going to be, who manages that pointer?
Q2: A vector might be more appropriate in place of an array. Or if going the array route anyway, returning a raw pointer is problematic. Because now you have used new in one place, and must bet that delete will be called appropriately later on. Using a smart pointer like shared_array or whatever would be more appropriate here.
i'm just trying to freshen up on my skills... here's what i got so far on the first problem...its wrong but i tried...
int main()
{
int myArray [5]={22,23,34,45,12,}
int *myArray = new int [size];
for ( int i = 0; i<size; i++)
{
cout<<(myArray+ i);
}
return myArray;
this is the first one...they havent covered vectors and they didn't cover it in my former C++ class so i'm not sure what to do now
Why do two declarations have the same name.
int *myArray and
myArray[5]
Try to work on the idea first and then start writing the code
Raghuram
its hard when you're going by Daniel Liang's style....its so computer science based and they're learning how to just hack at code--
Why do two declarations have the same name.
int *myArray and
myArray[5]
Try to work on the idea first and then start writing the code
Raghuram
Sign in to post your reply or Sign up for a free account.
Similar topics
by: KK |
last post by:
Hi Peoples,
Can anyone give me any learning materials for learning C++.
i.e. can you give me any docs or give me the link to any website that has
info on programming in general or C++.
(ok...
|
by: Kelly G. |
last post by:
I need to register a Vb DLL under restricted acess privilages please
provide me a solution.
Here is the complete issue:
I building a MSI using Vs.net ,One of the Dll's is Vb Component ( A shim...
|
by: Calvin KD |
last post by:
Hi everyone,
I need help urgently.
I have a C#.Net app which uses cookies for state management (since we've
gone away from Session for fear of webfarm and we haven't found the need for
SQL Server...
|
by: Calvin KD |
last post by:
Hi everyone,
I need help urgently.
I have a C#.Net app which uses cookies for state management. Everything has
been going fine until recently we've expanded the app
and a few more screens were...
|
by: uanmi |
last post by:
There is a patch to upgrade UAB2 to dotnet 2 on gotdotnet
But, as normal, there are no instructions on what to do to patch the
Microsoft UAB 2 install.
Can Microsoft please upgrade their UAB2...
|
by: Joonshik Kim |
last post by:
I was trying to define 3d array with pointer to pointer. I wrote like
following.
int ***d;
nx = 3;
ny = 5;
nz = 4;
d = (int ***)malloc((int) nx*sizeof(int **));
*d = (int **)malloc((int)...
|
by: ukwa |
last post by:
I have these codes that are supposed to load control arrays (days of week), there is only one textbox visible at design time, but I want to use control array to initialize the other six textboxes in...
|
by: deaconj999 |
last post by:
Hi All,
I am using this unbound to add the frequency to a date entered
=IIf(="HIGH - annual",+365,IIf(="MED - 3 yearly",+1095,IIf(="LOW - 5 yearly",+1825,IIf(="N/
A",Date()))))
but would...
|
by: dillipb |
last post by:
Please Reply Urgently
In the given string
'<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/${5}\"></param><param name=\"wmode\"...
|
by: ssniit |
last post by:
Please can anyone help me with d programs in C for treat the matter most urgent please please please please .................................!
CPU scheduling:
WAP to show FCFS scheduling...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |