Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Halp plz, C++

Name: Anonymous 2007-11-28 10:39

Hi /prog/, I have a problem...

I'm a noob at C++ (I learned it at school, so, yeah...) and I've got to make a program, which I find pretty difficult. i'm coming here seeking your help because I NEED a good grade if I want to validate my semester, and programming is highly coefficiented, so if you don't help me, i'm pretty much fucked...

So here's the deal:

Make a program which allows the input of a serie of integers and stocks them in a table, then display the table as it is and then display the table with the numbers sorted out in growing order...

I am a total noob at C (as I already mentioned) and I have no fucking clue about how to do this kind of shit.

So your help would be really, really, REALLY appreciated...
Pretty please?

Name: Anonymous 2007-11-28 10:45

int main(void)
{
    // Initialize a (list|table) here

    // Loop input collection function here
    // Append input to list or break loop if no more input

    // ::sort

    // Iterate through list and print to stdout

    return 0;
}


Fill in the blanks

Name: Anonymous 2007-11-28 10:46

>>2
Oh thank you that was soooooooooooooooooooooo helpful...

Name: Anonymous 2007-11-28 10:49

Look, I know I'm being a dick, but I really need a good grade!

The problem is that I have no fucking clue about how to sort the numbers in growing order (if that wasn't clear enough), so I don't know if you thought you were helping, but, well, you weren't.

Name: Anonymous 2007-11-28 10:51

You deserve to fail if you do not understand the material. That is how school works.

Name: Anonymous 2007-11-28 10:54

>>5
I understand every other material, so why should I fail for this one?

Name: Anonymous 2007-11-28 10:56

>>6
Because you don't understand this one.

Name: Anonymous 2007-11-28 10:59

OP should fail. Hard.

Name: Anonymous 2007-11-28 10:59

>>7
I understand your logic, but I want to understand how C++ works, and that was the first reason why I came here, so you could help me understand it better, thus making me able to write the program I need.

Name: Anonymous 2007-11-28 11:00

>>8
Why please?

Oh, and if any of you could actually HELP me, well, I'd be grateful

Name: Anonymous 2007-11-28 11:02

Here's a hint: ask the teacher.

Name: Anonymous 2007-11-28 11:03

>>10
What the fuck are you studying and why can't you program?

Name: Anonymous 2007-11-28 11:07

>>11
It's due for tomorrow, so that's not an option, unfortunately.

>>12
I'm in an institute of technology, studying electrical and electronical engineering, and computer science is part of it.

Name: Anonymous 2007-11-28 11:07

coefficiented, lol

Name: Anonymous 2007-11-28 11:08

>>14
Sorry if I made a mistake, I'm french and my english is not perfect

Name: Anonymous 2007-11-28 11:10

http://www.cs.brown.edu/people/jak/proglang/cpp/stltut/tut.html

Use version 2, as version 1 is too lame and version 3 is complicated enough to indicate that you plagiarised it.

Name: Anonymous 2007-11-28 11:40

/prog/ is for programmers, not for non-programmers trying to become such.

Name: Anonymous 2007-11-28 12:02

>>17
EXPERT PROGRAMMERS, even.

Name: Anonymous 2007-11-28 15:26

So frenchie still around?

Name: Anonymous 2007-11-28 15:32

>>19
yup, still haven't solved my problem (link provided by >>16 was helpful, but I can't use it, because we're supposed to use for, while, if and table only (sorry I didn't mention it firsthand)).

So, me and my friend are still working on it.

Name: Anonymous 2007-11-28 16:14

Look, I really need some help to get a good grade.  If I don't my parents will beat me again.

Name: Anonymous 2007-11-28 16:31

>>21
That's why we read SICP and learn to program on our own.

Name: Anonymous 2007-11-28 16:34

What's the problem here? Just write a trivial bubble sort and be done with it.

Name: Anonymous 2007-11-28 16:35

>>23
Only Jews choose bubblesort over quicksort.

Name: Anonymous 2007-11-28 16:39

>>24
You have two minutes to write a correct implementation of a sorting algorithm. If you fail, you will be brutally gangraped and then killed. YOUR CHOICE?

a. bubblesort
b. quicksort

Name: Anonymous 2007-11-28 16:42

>>25
what's bubblesort and quicksort?

>>23
The problem obviously is that I have no idea about how to sort the numbers... (I'm STILL working on it btw, but still, no idea (ones I had didn't work))

Name: Anonymous 2007-11-28 16:45

Just use Monads and lambda haskell over closed manifolds.

Name: Anonymous 2007-11-28 16:48

>>27
As if I had a clue of what you're talking about

Name: Anonymous 2007-11-28 16:48

Why not just use arrays to put the variables in.
And then sort them into another array?

Name: Anonymous 2007-11-28 16:49

>>26
OMG, what are you doing here?

Name: Anonymous 2007-11-28 16:52

The easiest way is to just input them on an array, then bubble sort them. Trust me, it can't get any easier than that.

Just search for "buble sort example". And you are on your way.

Do it, faggot.

Name: Anonymous 2007-11-28 16:56

ITT people who prefer bubble sort because they are afraid of full recursion.

Name: Anonymous 2007-11-28 16:58

Well, it's 23:00 where i live (that is to say in france), so i'm going to bed nao, but, remember this, I WILL BE BACK! tomorrow to be exact, I will poast the answer our teacher gave us, and submit it to your judgment.

Thanks to all of you who sincerely tried to help me, I will bump this thread tomorrow (if it still exists) otherwise I will just make another one.

Thank you and goodafternoon, it seems

Name: Anonymous 2007-11-28 16:59

>>33
DONY LISTEN TO BUBBLE LEIS

Name: Anonymous 2007-11-28 17:09

>>20
What do you mean by table?

Name: Anonymous 2007-11-28 17:10

>>32
We are not. We are just telling him the easiest way around it.

He could have coded it in 5 or 10 minutes.

Name: Anonymous 2007-11-28 17:10

>>33
Post your code here, and we may fix it.

Name: Anonymous 2007-11-28 17:10

I feel like we've all collectively failed.

Name: Anonymous 2007-11-28 17:13

>>38
I feel like you don't beling here.

Name: Anonymous 2007-11-28 17:16

MASSIVE BUMP!!

My good friend (roommate actually) just found this (it works, that's all I care about)

WARNING: The following content may cause eye bleeding to advance coder. Procede with extreme caution

So here it is:

#include <math.h>
#include <stdio.h>
#include <conio.h>

main()
{
      int i,j,min,min1,min2,min3,min4,min5,min6,min7;
      int tab[7];
      printf("entrez 7 valeures\n");
      for(i=1;i<=7;i++)
      {
                       scanf("%d",&tab[i]);
      }
      printf("%d %d %d %d %d %d %d\n",tab[1],tab[2],tab[3],tab[4],tab[5],tab[6],tab[7]);
      min=tab[1];
      for(i=1;i<=7;i++)
      {
                       if(tab[i]<min)
                       min=tab[i];
      }     
      for(i=1;i<=7;i++)
      {
                       if(tab[i]<min1)
                       {
                                      for(j=1;j<=7;j++)
                                      {
                                                       if(tab[i]>min && tab[i]<tab[j])
                                                       min1=tab[i];
                                                      
                                      }
                       }
                      
                      
                      
                      
      }
      for(i=1;i<=7;i++)
      {
                       if(tab[i]<min2)
                       {
                                      for(j=1;j<=7;j++)
                                      {
                                                       if(tab[i]>min1 && tab[i]<tab[j])
                                                       min2=tab[i];
                                                      
                                      }
                       }
                      
                      
                      
                      
      }
      for(i=1;i<=7;i++)
      {
                       if(tab[i]<min3)
                       {
                                      for(j=1;j<=7;j++)
                                      {
                                                       if(tab[i]>min2 && tab[i]<tab[j])
                                                       min3=tab[i];
                                                      
                                      }
                       }
                      
                      
                      
                      
      }
      for(i=1;i<=7;i++)
      {
                       if(tab[i]<min4)
                       {
                                      for(j=1;j<=7;j++)
                                      {
                                                       if(tab[i]>min3 && tab[i]<tab[j])
                                                       min4=tab[i];
                                                      
                                      }
                       }
                      
                      
                      
                      
      }
      for(i=1;i<=7;i++)
      {
                       if(tab[i]<min5)
                       {
                                      for(j=1;j<=7;j++)
                                      {
                                                       if(tab[i]>min4 && tab[i]<tab[j])
                                                       min5=tab[i];
                                                      
                                      }
                       }
                      
                      
                      
                      
      }
      for(i=1;i<=7;i++)
      {
                       if(tab[i]<min6)
                       {
                                      for(j=1;j<=7;j++)
                                      {
                                                       if(tab[i]>min5 && tab[i]<=tab[j])
                                                       min6=tab[i];
                                                      
                                      }
                       }
                      
                      
                      
                      
      }
    
      printf("%d, %d , %d, %d, %d, %d, %d, le min: %d\n",min,min1,min2,min3,min4,min5,min6,min);
      printf("%d, %d , %d, %d, %d, %d, %d le min: %d \n",min1,min,min3,min2,min5,min4,min6,min);
     
getch();
}



So, yeah, what do you think about it?

Name: Anonymous 2007-11-28 17:18

>>1
If I were you I wouldn't insult >>2, the answer he gave you was very helpful. Now, stop being brain-atrophied and learn how to think by yourself.

I am a total noob at C (as I already mentioned) and I have no fucking clue about how to do this kind of shit.

DA TEACHAR DIDN TEL ME HOW 2 DU DIS BUT I NO TEH TEORI TO LURN BY MYSELF OW 2 DO IT

how to sort arrays in a simple way for retarded dumbfucks :
Make an other array(newarray)
Get the biggest value of the array
in a loop in which i is the count, starts at 0 and stops when i is not smaller than the length of the array
{
Get the smallest value of the array and put it in newarray[i] then set array[i] to a bigger value than the biggest one
}
and return the new array

I just did everything for you, faggot.

http://en.wikipedia.org/wiki/Quicksort
http://en.wikipedia.org/wiki/Bubble_sort
http://en.wikipedia.org/wiki/Selection_sort

Name: Anonymous 2007-11-28 17:18

>>35
by table I meant 'un tableau' that is, something like a list or a table in which you can put numbers and stuff

Name: Anonymous 2007-11-28 17:19

Learn to fucking indent, I'll check it then.

Name: Anonymous 2007-11-28 17:24

>>41
I apologize to >>2, if I seemed rude (I probably was) it was only because I had a shitty day, blablabla personal life you don't care about. I know, I overreacted, and again, I apologize humbly.

Then, I don't know what arrays are (maybe they are what i call table, that would be horrible, but as I don't know the exact terms it is possible)




Holy shit, I just understood your post, for serious...

I'm baffled... O_O;;

Name: Anonymous 2007-11-28 17:32

Oh well, I'm off to bed, I can't even think clearly anymore.

Goodafternoon everyone

Name: Anonymous 2007-11-28 17:45

>>40
What the fuck?

That's hideous. Seriously, everything is wrong about that.

Name: Anonymous 2007-11-28 18:11

>>44
array = tableau
>>40
Hideous use what I answered in >>41

Name: Anonymous 2007-11-28 18:48

Fucking die in a fire you good-for-nothing fucking french faggot.

#include <iostream>
#include <vector>
#include <algorithm>

typedef NumT int;
typedef std::vector<NumT> ListT;

void print_list( const ListT& list ) {
    for ( ListT::const_iterator i = list.begin();
        i != list.end(); ++i )
        std::cout << *i << " ";
}

int main( int argc, char* argv[] ) {
    ListT list;   
    while( std::cin.good() ) {
        NumT tmp;
        std::cin >> tmp;
        list.push_back( tmp );
    }

    print_list( list );
    std::cout << std::endl;
    std::sort( list.begin(), list.end() );
    print_list( list );
}

Name: Anonymous 2007-11-28 19:22

HHAHAHA I LOVE THIS FRENCHY GUY ~♀~

Name: Anonymous 2007-11-28 19:43

>>48
"yup, still haven't solved my problem (link provided by >>16 was helpful, but I can't use it, because we're supposed to use for, while, if and table [i.e. arrays] only (sorry I didn't mention it firsthand))."

Name: Anonymous 2007-11-28 20:01


class Class {
  public static void main(String[] args) {
    ArrayList<Integer> a = new ArrayList<Integer>(1000);
    for (i : a) {
      i.add(Math.random() * Integer.MAX_VALUE);
    }
    System.out.println(a);
    mergesort(a);
    System.out.println(a);
  }
  //The rest of this code isn't even mine
    public static ArrayList<Integer> mergesort(ArrayList<Integer> numbers) {
        if (numbers.size() <= 1)
            return numbers;
        int middle = numbers.size() / 2;
        ArrayList<Integer> left = new ArrayList<Integer>();
        ArrayList<Integer> right = new ArrayList<Integer>();
        for (int i = 0; i < middle; i++)
            left.add(numbers.get(i));
        for (int i = middle; i < numbers.size(); i++)
            right.add(numbers.get(i));
        left = mergesort(left);
        right = mergesort(right);
        return merge(left,right);
    }
 
    public static ArrayList<Integer> merge(
            ArrayList<Integer> left, ArrayList<Integer> right) {
        ArrayList<Integer> result = new ArrayList<Integer>();
        while (left.size() > 0 && right.size() > 0) {
            if (left.get(0) < right.get(0)) {
                result.add(left.get(0));
                left.remove(0);
            } else {
                result.add(right.get(0));
                right.remove(0);
            }
        }
        if (left.size() > 0) {
            for (int i = 0; i < left.size(); i++)
                result.add(left.get(i));
        }
        if (right.size() > 0) {
            for (int i = 0; i < right.size(); i++)
                result.add(right.get(i));
        }
        return result;
    }
}

Name: Anonymous 2007-11-28 21:05

>>50
Oh, snap.

WELL I GUESS I'M A STUPID FAGGOT TOO FOR NOT CORRECTLY READING THE FUCKING QUESTION.

Name: Anonymous 2007-11-28 21:26

ITT: A future ENTERPRISE QUALITY PROGRAMMER who will specialize in web 2.0 modular extensible user-friendly deliverables.

Name: Anonymous 2007-11-28 23:40

GTFO. /prog/ is not your personal codemonkey.

Name: Anonymous 2007-11-29 12:55

hi everyone, it's me again!

About the code posted yesterday, i know it's shit, but I didn't care at the time because, well, strangely enough it worked, so I was content with it.

This morning, during the lesson, we worked on it (because noone had been able to find it), and we finally figured out how to do it.

So here it is, enjoy:

#include <stdio.h>
#include <math.h>
#include <conio.h>

main()
{
      int i,j,taille,b;
     
      printf("entrez la taille du tableau");
      scanf("%d",&taille);
      int tab[taille];
      printf("entrez %d valeurs",taille);
      for(i=1,i<=taille,i++)
      {
            scanf("%d",&tab[i]);
      }
      for(i=1,i<=taille,i++)
      {
            printf("%d",tab[i]);
      }
      for(i=1,i<=taille,i++)
      {
            for(j=1,j<=taille,j++)
            {
                    if(tab[i]<tab[j])
                    {
                          b=tab[i];
                          tab[i]=tab[j];
                          tab[j]=b;
                    }
            }
      }
      for(i=1,i<=taille,i++)
      {
            printf("%d",tab[i]);
      }
}

Well?

Name: Anonymous 2007-11-29 13:00

Since when do indexes begin at 1, faggot?

Name: Anonymous 2007-11-29 13:00

>>55
Not bad

Name: Anonymous 2007-11-29 13:06

>>56
I know they don't, it simply is easier that way. I told you I am not an advanced coder.

>>57
Thank you. Do you see any way in which it could be improved? (I'm sure you do, however, I understand if you don't care enough to post it and just let the thread die.

>>49
I love you too.

Name: Anonymous 2007-11-29 13:08

>>55
>>56 said it. Your code is broken. Otherwise, not bad. Separate the sorting part to a function, though.

Name: Anonymous 2007-11-29 13:12

>>59
We're going to see functions next week actually

Name: Anonymous 2007-11-29 13:15

>>60
Wow, they are deliberately TEACHING you to write spaghetti code from early on?

Name: Anonymous 2007-11-29 13:20

>>61
Well, yes they are. What i wrote in >>55 was the best code we ever wrote, but then again, I'm not in a programming school, it's just part of my cursus, and there is 90% chance that I won't use it when I leave the institute.

Name: Anonymous 2007-11-29 13:39

Thank god for that

Name: Anonymous 2007-11-29 13:44

int tab[taille];
...
for(i=1,i<=taille,i++)

Epic failure.

Name: Anonymous 2007-11-29 14:34

>>55
Lis le SIPI et deviens un PROGRAMMEUR EXPERT.

Name: Anonymous 2007-11-29 20:26

>>55
YOUR CODE IS NOT VALID ANSI C YOU FUCKING FAGGOT

     for(i=1,i<=taille,i++)
     {
           scanf("%d",&tab[i]);
once i = taille you will get a segfault

#include <stdio.h>
#define WITHEVERYELEMENT(count,length) for(count=0;count<(length);count++)

void sortArray(int *, int);

int main(int argc, char **argv)
{
    int longueur = 0;
    int * valeurs = NULL;
    int i = 0;
    int count = 0;
    printf("Entrez la taille du tableau : ");
    scanf("%i", &longueur);
    if(longueur<=0) exit(0);
    valeurs = malloc(sizeof(int) * longueur);
    WITHEVERYELEMENT(i,longueur)
        scanf("%i",&valeurs[i]);
    WITHEVERYELEMENT(i,longueur)
        printf("%i ",valeurs[i]);
    printf("\n\n");
    sortArray(valeurs,longueur);
    WITHEVERYELEMENT(i,longueur)
        printf("%i ",valeurs[i]);
    free(valeurs);
    return 0;
}


void sortArray(int * tableau,int longueur)
{
    int i = 0;
    int j = 0;
    int ind = 0;
    int * buffer = malloc(sizeof(int) * longueur);
    int maxVal = 0;
    int minVal = 0;
    WITHEVERYELEMENT(i,longueur)
        buffer[i] = tableau[i];
    WITHEVERYELEMENT(i,longueur){if(maxVal < tableau[i])maxVal=buffer[i];}
    WITHEVERYELEMENT(i,longueur)
    {
        minVal = buffer[0];
        ind = 0;
        tableau[i] = buffer[0];
        WITHEVERYELEMENT(j,longueur)
        {
            if(minVal>buffer[j])
            {
            tableau[i] = buffer[j];
            minVal = buffer[j];
            ind = j;
            }
        }
        buffer[ind] = maxVal;
    }
    free(buffer);
}


Name: Anonymous 2007-12-02 0:00

I think its stupid

Name: Anonymous 2007-12-02 16:01

>>1
I've got to make a program, which I find pretty difficult.

Name: Anonymous 2007-12-03 4:55

>>40
isn't it plain C?

Name: Anonymous 2007-12-03 5:33

#define WITHEVERYELEMENT(count,length) for(count=0;count<(length);count++)
Ugh.

Name: Anonymous 2009-03-18 2:33

I'm feeling really keen, for some of that good ol' green

Marijuana MUST be legalized.

Name: Trollbot9000 2009-07-01 8:29

O fix that bug.

Name: Anonymous 2011-02-04 15:14


Don't change these.
Name: Email:
Entire Thread Thread List