| | |
template in c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2009
Posts: 15
Reputation:
Solved Threads: 0
hi
Write an overload function "searchArray" so that it takes an
array "ary" of int or char, and additional argument,
namely "valu" with type as same as the "ary". A call to this
function will return the index of "valu" within "ary" or -1
if it does not exist.
and this is what i could write for now ..
it's not complete ..
any one can help me and make it 100% work
thanks
Write an overload function "searchArray" so that it takes an
array "ary" of int or char, and additional argument,
namely "valu" with type as same as the "ary". A call to this
function will return the index of "valu" within "ary" or -1
if it does not exist.
and this is what i could write for now ..
C++ Syntax (Toggle Plain Text)
int searchArray ( int ary[ ],int a){ for ( int i=0;i<=ary.length;i++){ if (ary[i]== a) return i; else return -1; } }
it's not complete ..
any one can help me and make it 100% work
thanks
1
#2 Oct 10th, 2009
for the general search function, take the
If you google C++ templates you'll find a wealth of information on how to use them - as well as, maybe, reading your textbook? Take a stab at it and show us your work then.
else return -1 out of the for loop. That return statement should only execute if you complete the for loop and don't find the search value.int ary[] does not have a length member. You will have to pass the array length as an additional parameter.If you google C++ templates you'll find a wealth of information on how to use them - as well as, maybe, reading your textbook? Take a stab at it and show us your work then.
Last edited by vmanes; Oct 10th, 2009 at 1:50 am.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- template-doesn't compile (C++)
- template formal parameter (C++)
- Looking for a professional Graphic Template Designer (Web Development Job Offers)
- Invalid add-in template (Windows NT / 2000 / XP)
- Smart client template solution ??? (ASP.NET)
- vb trainer template (Visual Basic 4 / 5 / 6)
- Using a Folder Type as a Template (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: Do/While Loop help
- Next Thread: C++ problem
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






