i have this assignment due tommorow ive tryed it but it seems tuffer than what it should. anyone have any ideas?

Write a function stage 1() that reads one of Tommy’s data files into a suitably declared and named
data structure. You should assume that there will be at most 100 rows in any given data file.
After reading the data file, your function should report (yes, the functions developed as part of this
project will have scanf and printf calls in them) the total number of towers in this model, and the sum
of their transmit powers, in Watts. Sample output for all stages is given below.
Be sure to make appropriate use of the #define and typedef facilities. Think carefully about how
your function should interface with the main program, and choose an appropriate set of parameters and
appropriate return type/value.

i still have another 5 stages but they all depend on this .


this is wat ive done:


[/* stage 1 */

#include<stdio.h>
/* size of array */
#define ROWS 100
#define DIST 1000

/* stage 1 function is meant to read values inputed and clculate the power and number of towers. */

double stage_1(double[],double[],double);

int
main(int argc, char **argv) {

return 0;
}

double
stage_1(double X[], double Y[] , double *powert ) {
int row, next;
double distx, disty, *powert;

/*initalise varibles */
distx=0.0;
disty=0.0;
pt=0.0;
row=0;

printf("Enter Distance in the x direction and y direction (max DIST %d)\n"
" of each tower : ", DIST);
scanf("%lf %lf %lf ", &distx,disty, pt);
/*now a number has been put in now calculate the number of towers*/
if (n == ROWS){
n = next/3;
n += 1;
}
return n;

printf("Data file describes %lf towers, of total capacity Watts \n", n);
} ]

Recommended Answers

All 4 Replies

sorry i forgot to add the background,, an ill also put it a sample input and ouput.

Tommy the Telecommunications Tuner
Tommy the telecommunications tuner works for a large networking company. Tommy is responsible
for identifying possible locations for network towers for the company’s mobile phone network, and for
making sure that there are no black spots in which there is no coverage. Tommy has studied Electrical
Engineering at the University, and has been told that when a mobile phone transmitter t has power Pt
(in Watts), then the available power Pd (also in Watts) at a distance d (in meters) from the tower can be
approximated by
Pd =
Pt
(1 + (d/10))4 ,
where in combination the two constants 10 and 4 reflect the dispersion of the signal as the distance from
the base station increases, and the absorption of the signal by the intervening atmosphere. (In particular,
the inverse-square law on power that would arise if the transmitter was a point source and in a vacuum
does not apply. The difference is caused by energy absorption in the atmosphere, and interference that
arises between a reflected ground wave and the primary signal. Study advanced telecommunications
engineering if you want to know more.)
Signals from different towers use different frequencies, and neither reinforce each other nor conflict
with each other. A mobile phone is “in range” of a tower if it receives the signal from that tower at a
power level greater than some minimum Wattage Pmin. In this work we will assume that Pmin = 10−6
Watts, and that the power output from a base station is fixed. (In practice, the base station can vary its
power and “reach out” to a distant phone, and the phone can – within limits – save energy by decreasing
its sensitivity when the signal is strong, but we are going to ignore those options in this project.)
Tommy is primarily interested in designing a mobile phone network covering the island of Sqone, a
one kilometer square island located in the Sea of Ignorance that until now has relied on carrier pigeons
for communications. As a model of the proposed network, he has a data file that contains four columns:
a one-character identifier for a phone base station; the x location (in meters from the south-west corner
of the island) of that base station; the y location (in meters, again from the south-west corner) of that
base station; and the Wattage Pt for that base station. For example, the two data rows
A 500.0 500.0 0.50
f 1000.0 0.0 0.25
represent a phone base station labeled A in the center of Sqone, with a 0.5 Watt signal strength, and
another base station labeled f of half that strength located in the south-east corner. Tommy’s data files,
one for each possible model of Sqone’s mobile phone network, contain one such data row for each base
station that is being suggested as part of that particular model.
What Tommy wants – and what you are to deliver in this project – is a program that helps Tommy
visualize each of the proposed network layouts, and alert Tommy to any black spots that might arise.


and the results should look like:

[Data file describes 4 towers, of total capacity 4.10 Watts]

can anyone please help??
i changed it to this upon thinking about the program however it doesnt work?

/* Stage 4 */

typedef struct StationStruct {
        char id; /* a one-character identifier for a phone base station*/
        float x; /* the x location*/
        float y; /* the y location*/
        float watt; //Wattage Pt*/
} Station;


int readStation(FILE *fh, Station *s);

int readStations(FILE *fh, Station stations[]);


#define MAX_STATIONS 100
int
main(int argc, char **argv) {
        Station stations[MAX_STATIONS];
        int stationsRead;
        float powert;
        printf("Enter Tower name , distance in the x direction, distance in the y directionand the power:");
        scanf("%c   %f    %f",&id ,&x, &y, &watt);
        StationStruct(id,x,y,watt);
        printf("Data file describes %c towers, of total capacity %0.2f Watts",id,powert);
        return 0;
}

Can you be more specific of what kind of help do you need ? Are there compile time errors, run time errors or do you need help to design the algorithm ?

[...]
Tommy the Telecommunications Tuner
Tommy the telecommunications tuner works for a large networking company. Tommy is responsible
for identifying possible locations for network towers for the company’s mobile phone network, and for
making sure that there are no black spots in which there is no coverage.[...]

Seems an exceptional telecommunications tuner's kind of guy.

You are failing at grasping the concept of structures.

#include <stdio.h>
#include <string.h>

typedef struct {
    int age;
    float height;
    char name[50];
}Person;

/* example tester */
int main (void)
{
    /* create an empty Person record */
    Person somebody;

    /* somebody is 28 years old */
    somebody.age = 28;

    /* somebody is 5.8 inches tall */
    somebody.height = 5.8f;

    /* who's somebody? */
    strcpy(somebody.name, "Jessica Biel");
    /* can not just somebody.name = "Jessica Biel"; */

    /* display Jessica's information */
    printf("Who's this?: %s\n", somebody.name);
    printf("How tall?: %.2f\n", somebody.height);
    printf("How old?: %d\n", somebody.age);

    return 0;
}

How would you insert the data via user input, instead of direct hard code assignments? Change mystery_bit for the proper variable.

scanf("%d", &mystery_bit); /* if somebody.age */
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.