Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,656 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,179 people online right now. Registration is fast and FREE... Join Now!




Need help with examination solution!

 
Reply to this topicStart new topic

Need help with examination solution!, Read the thread before putting curses on me!

FrozenSnake
post 4 Sep, 2008 - 06:59 PM
Post #1


D.I.C Head

**
Joined: 30 Jul, 2008
Posts: 55


My Contributions


To prevent flaming for cheating or anything else
Here is proof that the examination is accessible for anyone and that it's a old one
http://www.ida.liu.se/~TDIU04/exam/old_exams/080314/?C=N;O=D
To prevent flaming for cheating or anything else

This is a solution example source for a examination @ Linköping University.
The problem is that it wont compile. Error message below source.
Before contacting the teacher to ask for a correction I wanna try here.

I am not a student at LIU. I wanna use this examination to measure my
own knowledge and when there is no correct "answer" to look at when
I am correcting myself to see what I need to read more about etc.

CODE
/*
* uppgift1.cc    TDIU04 2008-08-22, uppgift 1.
*/
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
using namespace std;

int main()
{
   istream_iterator<int> input(cin);
   istream_iterator<int> end;

   vector<int> v(input, end);

   copy(v.begin(), v.end(), output);
   cout << "\n\n";

   ostream_iterator<int> output(cout, " ");

   sort(v.begin(), v.end());

   v.erase(unique(v.begin(), v.end()), v.end());

   copy(v.begin(), v.end(), output);
   cout << "\n\n";

   int five_percent = static_cast<int>(0.05 * v.size());

   cout << "5% = " << five_percent << " tal\n\n";

   v.erase(v.end() - five_percent, v.end());
   v.erase(v.begin(), v.begin() + five_percent);

   copy(v.begin(), v.end(), output);
   cout << "\n\n";

   int sum = accumulate(v.begin(), v.end(), 0.0);

   cout << "summa = " << sum << "\n\n";
   cout << "medelvärde = " << static_cast<double>(sum) / v.size() << "\n\n";

   return 0;
}


In function `int main()':|
18|error: `output' undeclared (first use this function)|
18|error: (Each undeclared identifier is reported only once for each function it appears in.)|
40|warning: converting to `int' from `double'|

I use code::block with GNU GCC Compiler
Anyone know how to declare output to make it compile?

This post has been edited by FrozenSnake: 4 Sep, 2008 - 07:04 PM
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 4 Sep, 2008 - 08:12 PM
Post #2


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,858



Thanked 47 times

Dream Kudos: 550
My Contributions


well if you move the declaration of output to before the line with the error then the code compiles...

put: ostream_iterator<int> output(cout, " ");

before the line: copy(v.begin(), v.end(), output);

It seems to work for me, it will calculate 5% of the number of entries, and give a sum and an average.

User is offlineProfile CardPM

Go to the top of the page

FrozenSnake
post 5 Sep, 2008 - 07:34 AM
Post #3


D.I.C Head

**
Joined: 30 Jul, 2008
Posts: 55


My Contributions


Thanks for the help :]
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 05:31AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month