[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

C++ Vector as a class private member

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 18
Thread images: 2

File: index.png (4KB, 212x238px) Image search: [Google]
index.png
4KB, 212x238px
How would you make a class that has a vector of integers as its' private data member. And exactly how would you implement certain member functions in that class to obtain the largest, smallest, and average of that vector of integers? I'm not quite sure how to write the header or the implementation files for this class?
>>
Should have paid attention in lectures friendo.
>>
choose a new major/degree OP

If you can't do that - there's no hope, your parents won't mind

It's like a fireman asking what is water
>>
Dude this stuff is literally first semester CS. There's nothing about std::vector that makes it not able to be a private member.
>>
>>61191370
make a class that holds a vector of integers as a private data member

after that implement methods to find the largest, smallest and the average member

there you go, its really simple
>>
>>61191597
I guess I should rephrase my question.
I'm suppose to make a vector a private member (ok, so I know how to do that)
but the specifications asks for me to make function setIntValue, but doesn't tell me what it is suppose to do.
A vector is just an ordered collection of elements like a deque and a list. But, am I to just add an element in setIntValue, or what?
>>
>>61191597
Nothing to hide?
>>
or set the value of just one of it's element?
>>
>>61191370
Just make a private vector and implement functions to do what you ask. What even is your question?
>>
>>61191633
ask the person who made the specifications? are you dumb?
>>
>>61191633
Never make a function called setIntValue
-"Value" is unnecesary for POD type like int
-set "int" value? Which int? If the class has two ints - foo and bar which is it setting? How do you name other function setIntTwo? Use setFoo and setBar.
setIntValue implies a singular int, not a vector of them
>>
File: 1370687313430.jpg (115KB, 1024x768px) Image search: [Google]
1370687313430.jpg
115KB, 1024x768px
>>61191633
>setIntValue()

10/10 function naming

your lecturer sure is a pro
>>
>>61191370
This thread smells of curry.
>>
>>61191370
These are the only acceptable implementations.
>largest
std::max_element(v.begin(), v.end())
>smallest
std::min_element(v.begin(), v.end())
>average of that vector of integers
std::accumulate(v.begin(), v.end(), 0) / v.size()
>>
>>61191807
Are they in <algorithm>?
>>
>>61191807
Congrats on doing OP's homework for him, now he's learned nothing except how to continue leech off of others.
>>
>>61191837
Less competition for me. =)
>>
I'm surprised that no-one has pointed out that OP is an underage elementary school student.

>>61191370
>I'm not quite sure how to write the header or the implementation files for this class?
Dude. Google before you start a whole fucking thread on /g/. Learn to think critically. Trust me, it's great
Thread posts: 18
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.