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 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) ;
}

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