Originally posted by gpraghuram
Please help urgently!
Collapse
X
-
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.Originally posted by deltamami0999i'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,1 2,}
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
int *myArray and
myArray[5]
Try to work on the idea first and then start writing the code
RaghuramLeave a comment:
-
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,1 2,}
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
Originally posted by oler1sIf 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.Leave a comment:
-
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.Leave a comment:
-
i do, but i'm stuck.....can you help me figure this out?
Originally posted by Ganon11Regardless 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?Leave a comment:
-
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?Leave a comment:
-
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
Originally posted by StudlyamiNow 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.Leave a comment:
-
Now its "you have to show the rest of the class", but it has to be done by midnight? hmm.Can someone help me explain these problems? I'm trying to teach my little brother how to code these ...
We are not here to do your home work for you so don't ask.Leave a comment:
-
Please help urgently!
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 TrainingTags: None
Leave a comment: