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 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.

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