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

wtf?

Name: newfag 2010-11-04 0:45

hey all, im a newfag at programming and im taking a year one programming course at the university, (im year 3 maths) and i need sone help i have no idea wtf to do and my teacher speaks borderline english.

i need to make this program below using call by referance instead of call by value, i have no idea how to do this, so if anone could get me started,,, or anything i would really appriciate it =)



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

double washerweight(int, double, double, double, double, double);
double circlearea(double, double);
void printweight(char, int, double, double, double);

void main(void)
{

double washer1 = 'A', washer2 = 'B', washer3 = 'C', washer4 = 'D';
int q1, q2, q3, q4;
double t1, t2, t3, t4;
double d1, d2, d3, d4;
double dA1, dA2, dB1, dB2, dC1, dC2, dD1, dD2;
double pi = 3.14159265;

double weight1, weight2, weight3, weight4;
double total_weight;
double area1, area2, area3, area4;

printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type A : \n");
scanf("%d %lf %lf %lf %lf", &q1, &t1, &d1, &dA1, &dA2);
printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type B : \n");
scanf("%d %lf %lf %lf %lf", &q2, &t2, &d2, &dB1, &dB2);
printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type C : \n");
scanf("%d %lf %lf %lf %lf", &q3, &t3, &d3, &dC1, &dC2);
printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type D : \n");
scanf("%d %lf %lf %lf %lf", &q4, &t4, &d4, &dD1, &dD2);

weight1 = washerweight(q1, t1, d1, dA1, dA2, pi);
weight2 = washerweight(q2, t2, d2, dB1, dB2, pi);
weight3 = washerweight(q3, t3, d3, dC1, dC2, pi);
weight4 = washerweight(q4, t4, d4, dD1, dD2, pi);
total_weight = weight1 + weight2 + weight3 + weight4;

printf("Washer Type \t Qty \t Thickness \t Desity \t Weight \n ") ;
PrintWeight(washer1, q1, t1, d1, weight1);
PrintWeight(washer2, q2, t2, d2, weight2);
PrintWeight(washer3, q3, t3, d3, weight3);
PrintWeight(washer4, q4, t4, d4, weight4);
printf("********************************************** \t %0.2f \n", total_weight);
}

double washerweight(int q, double t, double d, double d1, double d2, double pi)
{
double area, iarea, oarea, weight;
oarea = circlearea(&d2,pi);
iarea = circlearea(&d1, pi);
area = oarea - iarea;
weight = q * t *d * area;
return (weight);
}

double circlearea(double d, double pi)
{
double rad;
rad = d/2.0;
return (pi * rad * rad);
}

void printweight(char washer, int q, double t, double d, double weight)
{
printf("%c \t \t %d \t %0.2lf \t \t %0.2lf \t %0.2lf \n ", washer, q, t, d, weight) ;
}

Name: Anonymous 2010-11-04 1:01

Sorry, can't help you there. Maybe try /adv/.

Name: Anonymous 2010-11-04 1:02

Why not just use FORTRAN if you're going through so much trouble?

Name: Anonymous 2010-11-04 1:48

*sigh* I'm too tired to scald you for using /b/ terminology and not applying the [code] tags.

Name: Anonymous 2010-11-04 2:07


#include <stdio.h>
#include <math.h> /* useless to include if you don't use M_PI, other macros and/or functions */

double washer_weight(int* q_ptr, double* t_ptr, double* d_ptr, double* d1_ptr, double* d2_ptr, double* pi_ptr);
double circle_area(double* d_ptr, double* pi_ptr);
void print_weight(char* washer_ptr, int* q_ptr, double* t_ptr, double* d_ptr, double* weight_ptr);

/* (1). extend your program for n washers instead of 4 */
/* (2). coffee */
/* (3). I hope you get the point(er), get it? */
int main(void)
{
    double washer1 = 'A', washer2 = 'B', washer3 = 'C', washer4 = 'D'; /* aw what the fuck */
    int q1, q2, q3, q4;
    double t1, t2, t3, t4;
    double d1, d2, d3, d4;
    double dA1, dA2, dB1, dB2, dC1, dC2, dD1, dD2;
    double pi = 3.14159265; /* double pi = M_PI; */

    double weight1, weight2, weight3, weight4;
    double total_weight;
    double area1, area2, area3, area4;

    printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type A : \n");
    scanf("%d %lf %lf %lf %lf", &q1, &t1, &d1, &dA1, &dA2);
    printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type B : \n");
    scanf("%d %lf %lf %lf %lf", &q2, &t2, &d2, &dB1, &dB2);
    printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type C : \n");
    scanf("%d %lf %lf %lf %lf", &q3, &t3, &d3, &dC1, &dC2);
    printf("Enter quantity, thickness, density, inner diameter, outer diameter of Washer Type D : \n");
    scanf("%d %lf %lf %lf %lf", &q4, &t4, &d4, &dD1, &dD2);

    weight1 = washer_weight(&q1, &t1, &d1, &dA1, &dA2, &pi);
    weight2 = washer_weight(&q2, &t2, &d2, &dB1, &dB2, &pi);
    weight3 = washer_weight(&q3, &t3, &d3, &dC1, &dC2, &pi);
    weight4 = washer_weight(&q4, &t4, &d4, &dD1, &dD2, &pi);
    total_weight = weight1 + weight2 + weight3 + weight4;

    printf("Washer Type \t Qty \t Thickness \t Desity \t Weight \n ") ;
    print_weight(&washer1, &q1, &t1, &d1, &weight1);
    print_weight(&washer2, &q2, &t2, &d2, &weight2);
    print_weight(&washer3, &q3, &t3, &d3, &weight3);
    print_weight(&washer4, &q4, &t4, &d4, &weight4);
    printf("********************************************** \t %0.2f \n", total_weight);

    return 0;
}

double washer_weight(int* q, double* t, double* d, double* d1, double* d2, double* pi)
{
    auto double iarea = circle_area(d1,pi), oarea = circle_area(d2,pi), area = oarea - iarea;
    return (*q)*(*t)*(*d)*area;
}

double circle_area(double* d, double* pi)
{
    auto double rad = (*d)/2.0;
    return (*pi)*rad*rad;
}

void print_weight(char* washer, int* q, double* t, double* d, double* weight)
{
    printf("%c \t \t %d \t %0.2lf \t \t %0.2lf \t %0.2lf \n ", *washer, *q, *t, *d, *weight) ;
}

Name: Anonymous 2010-11-04 2:32

>>1
Good evening gentlemen. I'm a beginner at the art of programming and I'm having a programming course at the university I'm attending. I have 3 years of experience in the art of mathematics and therefore, I, the wizards apprentice, ash Thou for your help with arcane magic. For that sake, I have no clue on mixing the ingredients for achieving a high quality potion. My dear wizard beholds a curse of partial REGULAR EXPRESSIONS.

I need to write a scroll, as it is seen below, using the spells of call by reference instead of scrolls of call by value. I therefore urge you to help me, a brother of your kind. If any of you master wizards could point me a direction to the source of my error, or similar, I would appreciate it and express it with glee.

A brother of arcane magic; Ahniuse.

Name: Anonymous 2010-11-04 2:38

>>1
void main
Stopped reading right there. Maybe you should ask your lecturer not to use programming idioms from 20 years ago.

Name: Anonymous 2010-11-04 2:57

>>7
He's just old-skool; nothing wrong with that brother.

Name: Anonymous 2010-11-04 3:46

Name: Anonymous 2010-11-04 4:11

I recommend grokking K&R it's pointers chapter is unmatched.

Name: VIPPER 2010-11-04 4:21

LETS POST JEWS INSTEAD

Name: Anonymous 2010-11-04 4:21

>>7
The funny part is that int main(void) and int main(int argc, char *argv[]) were standardized more than 20 years ago.

Name: Anonymous 2010-11-04 4:21

>>6
My good sir, I must commend you for your majestic use of words. It was a splendid display of using your intellect to get your point across. If only the poser who originally stared this thread had posed his question with equal splendor, the masters here surely would have shared their knowledge of the arts.

Name: Anonymous 2010-11-04 4:55

>>5
double washer1 = 'A', washer2 = 'B', washer3 = 'C', washer4 = 'D';
auto double

wtf, OP

Name: Anonymous 2010-11-04 5:20

C is always pass by value. Get over it, ``faggot''.

Name: Anonymous 2010-11-04 6:53

>>5,13,14,15

    #include <stdio.h>
    #include <math.h> /* not useless any more */
    #define N_STAR 1024

    double washer_weight(int* q_ptr, double* t_ptr, double* d_ptr, double* d1_ptr, double* d2_ptr, double* pi_ptr);
    double circle_area(double* d_ptr, double* pi_ptr);
    void print_weight(char* washer_ptr, int* q_ptr, double* t_ptr, double* d_ptr, double* weight_ptr);

    /* 1: extend your program for n washers (partial done, needs more args rather than macro) */
    /* 2: coffee, chewing gum */
    /* 3: the anwser is &(*ptr) = ptr */
    /* 4: extensions up in this magic scroll */

    int main(void)
    {
        auto signed int i, limit, q[N_STAR];        /* i = iterator, limit = amount of washers, q = quantity    */
        auto double tau[N_STAR], rho[star];        /* tau = thickness, rho = density; all in arrays        */
        auto double inner_d[N_STAR], outer_d[N_STAR];    /* inner_d(iameter), outer_d(iameter); all in arrays        */
        auto double sum_w = 0, weight[N_STAR] = {0};    /* sum_w = sum of the weights & individual weights in array     */
   
    printf("%s%s","please enter the amount of","washers: ");
    scanf("%i",&limit); putc('\n');
    if (limit <= 0) {
        for (i = 0; i < limit && limit < N_STAR; ++i) {
                printf("%s %s, %s %s, %s %s, %s, %s, %s (%s): ",
                       "please enter the","quantity","thickness","(tau)","density","(rho)",
                "inner diameter","outer diameter","of washer","data must be spaced");
                scanf("%d %lf %lf %lf %lf",&q[i],&(*(tau+i)),rho+i,inner_d+i,outer_d+i);
            cur_weight = washer_weight(&q[i],&(*(tau+i)),rho+i,inner_d+i,outer_d+i);
            weight[i] = cur_weight;
            sum_w += cur_weight;
            putc('\n');
        }
    } else {
        printf("%s: %i\n","the amount of washers is not a valid; size");
        return 1;
    }

        printf("washer type \t quantity \t thickness \t desity \t weight \n","",,,);
    for (i = 0; i < limit && limit < N_STAR; ++i)
        print_weight(*i, q+i, tau+i, rho+i, weight+i);
        printf("********************************************** \t %0.2f \n", total_weight);

        return 0;
    }

    double washer_weight(int* q, double* t, double* d, double* d1, double* d2)
    {
        return  *q <= 0 || *t <= 0 || *d <= 0? 0 : (*q)*(*t)*(*d)*(circle_area(d2)-circle_area(d1));
    }

    double circle_area(double* d)
    {
        return *d <= 0? 0 : M_PI*pow((*d)/2,2);
    }

    void print_weight(char* washer, int* q, double* t, double* d, double* weight)
    {
        printf("%i \t \t %d \t %0.2lf \t \t %0.2lf \t %0.2lf \n",*washer,*q,*t,*d,*weight);
    }


This scroll might include side-effects and/or random morphing when used. Take care.

>>11, 15
We shall see you as an object that is utterly useless and does not belong in the library of /magic/. You will not catch us with your lies, because we are not fish.

Name: Anonymous 2010-11-04 11:53

>>5
YHBT. M_PI is not defined in math.h. Actually it's not defined anywhere in standard. All your life was a lie. If kid is compiling his shit with ms troll stduio, he will be fucked. But then. I'm okay with it.

Name: Anonymous 2010-11-04 14:51

>>16
Please optimize your quoting !!

Name: Anonymous 2010-11-04 21:19

"call by reference"
I assume he means use a reference parameter. So do it, you nigger.

void op(bool IsAFaggot);
to
void op(bool &IsAFaggot);

Name: Anonymous 2010-11-04 21:43

>>19
because that shitty references are supported by C, so doing ``voig op(bool &IsAFaggot)'' will compile.

Also,
op is a faggot.
go back to /b/.

HIBT?

Name: Anonymous 2010-11-04 22:09

>>18
He did, with -O1. Unfortunately -O1 is of course typically only acceptable for beta testing, and the /prog/ standard for point-release posts is gbbcc -O3 -D_GNAA_SOURCE -D_IVE_READ_SICP -faggot-quotes -fno-exceptions.

Name: Anonymous 2010-11-04 22:49

             / ̄∧_∧ ̄ ̄ ̄ // ̄\\
       __ ⊂/__(´∀` )__  /_⊃___| |\フ ヽ  CFLAGS JUST KICKED
   ,  ´_  /   / ̄ ̄ __ / ̄ ヽ    __ヽ ̄ ̄ |  IN, YO!
  /∠__/―/-。―/――∠_/__∧  |       | ∧_.| 
  ,========――´=============/⌒ヽ=|.=====| | ヽ ̄〕 
  | _   |GENTOO|    _  ″  |⌒| |/   __ /|  )ノ    vroom
  )_旧_∈≡≡≡≡∋_旧_″_|| ノ丿_ -――┘ 丿      vroom!
   \ \_ノ  ̄ ̄ ̄三三三\ \_ノ    三三三三 
    三三三三三三三三三三三三三三三三三三三三三三三三
       三三三三三三三三三三三三三三三三三三三三三三三
          三三三三三三三三三三三三三三三三三三三三三三三三三三
                  三三三三三三三三三三三三三三三三三三
                        三三三三三三三三三三三

Name: Anonymous 2010-11-05 1:39

double washer1 = 'A', washer2 = 'B', washer3 = 'C', washer4 = 'D';

IHBT

Name: Anonymous 2010-11-05 1:43

>>20
Fuck off, ``faggot''.

Name: Anonymous 2010-11-05 6:22

>>20
Actually due to the latest revisions for abbreviation meanings, it's HIGBT? or, the more natural DIHBT?

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