4 Replies - 895 Views - Last Post: 03 September 2008 - 04:49 AM Rate Topic: -----

#1 awanz89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-September 08

i need help in my take home assignment

Posted 03 September 2008 - 01:06 AM

I need help in my take home assignment I dont understand on how to write the prog... Can anyone help me

below here is the question
anyone who wish to help may contact me awanz89@yahoo.com
either email or YM! awanz89
i do have a part of the source code that i know in doing the read text.file or write a text file

attached is the assignment question Attached File  asking_help_from_the_net.doc (43.5K)
Number of downloads: 70
below here also my code... just a part of it... I am still in blurred on how to do it.. Please help me...

#include<stdio.h>

struct TNode{
	double x,y;
};

TNode *Nodes;
int NumNodes;
int main(int argc,char *argv[])
int k;

{

FILE *fp;

fp=fopen("Node.data"."r");
if(fp==NULL)

	
	{return -1;}

	fscanf(fp,"%d",.&NumNodes);
	Nodes=new TNode(NumNodes);

	k=0;
	while(!feof(fp))
	{
		fscanf(fp,"%f%f",&Nodes[k].x, &Nodes[k].y);
		k++;
	}
	fclose(fp);








In mathematics and computer science a graph is a set of objects called points, nodes, or vertices connected by links called lines or edges. A link between two nodes indicates that the nodes are neighbours of each other. This program will determine whether a randomly generated graph is fully connected.
Input: Maximum dimensions of an area (Xmax, Ymax), Number of nodes N, and distance D.
Program function:

1. Each node has a unique numeric identifier, which should be in the range from 0 to N-1.
2. Distribute the nodes in the given area randomly, such that each node has a position (x, y).
3. Each node is considered a neighbour to another node if the distance between them is less than D.
4. Determine if the graph is considered fully connected. A graph is considered fully connected if there exists a path between every pair of nodes in the graph.
Output:
1. Print the coordinates for each of the nodes to a text file. The text file must be in the following format:
<Node ID> <X> <Y>. For example,
0 3.22 4.22
1 1.45 2.34
2 2.42 4.23

2. Print a statement to indicate whether the graph is fully connected.

Hints:
1. Use array for graph implementation
2. Google keywords: breadth-first search and depth-first search.

Examples:

(a) In the follow graph, the distance of node 4 to any other nodes is larger than the given distance, D. Thus, it has no neighbour. Since node 4 is isolated from other nodes, the graph is NOT fully connected.










(B) In the following example, the distance between node 0 and node 4 is smaller than D. Thus node 0 and node 4 are neighbours. The resultant graph is FULLY connected.



In the following example, the graph is partitioned into two clusters. Thus, it is also NOT fully connected.

** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: i need help in my take home assignment

#2 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5061
  • View blog
  • Posts: 26,433
  • Joined: 10-May 07

Re: i need help in my take home assignment

Posted 03 September 2008 - 01:09 AM

... what is this ?

int k;

{

FILE *fp;



You need to give your function a name, you can't just have floating brackets lying around in your code. Plus, you must have a function main somewhere. I'm guessing that is what this should be.
Was This Post Helpful? 0
  • +
  • -

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1376
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: i need help in my take home assignment

Posted 03 September 2008 - 03:53 AM

int k should be declared after that bracket. The bracket should immediately follow int main (int argc, char *argv[])

Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#4 awanz89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-September 08

Re: i need help in my take home assignment

Posted 03 September 2008 - 04:08 AM

View Postno2pencil, on 3 Sep, 2008 - 01:09 AM, said:

... what is this ?

int k;

{

FILE *fp;



You need to give your function a name, you can't just have floating brackets lying around in your code. Plus, you must have a function main somewhere. I'm guessing that is what this should be.


what the thing that u said? i dont understand :(


ooh ok.... but i need some help to continue write the prog

i know that i have to use structure, arrays and for loop but how :(
Was This Post Helpful? 0
  • +
  • -

#5 sensui  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 146
  • Joined: 24-August 08

Re: i need help in my take home assignment

Posted 03 September 2008 - 04:49 AM

I've edited a bit your program ( now it works ).
#include <stdio.h> //for printf()

struct TNode {
    double x, y;
};

int main( int argc, char *argv[] ) {
    //you must declare these variables local not global
    //only constants are declared global
    TNode * Nodes;
    int NumNodes;

    int k; //later k is used as a count variable ( in the while loop )
    //always initialize your pointers with NULL even if you don't use them
    FILE * fp = NULL;

    //don't use . ( point ) when giving arguments to functions
    //use , ( comma ) for that

    fp = fopen( "Node.data", "r");
    if ( fp == NULL ) {
        return -1;
    }

    fscanf( fp, "%d", &NumNodes );

    //operator new has the following syntax:
    //int * pointer = new int [NumNodes];
    //note that you can use any type instead of int
    //even user defined types like Nodes
    Nodes = new TNode [NumNodes];

    k = 0;
    while ( !feof( fp ) ) {
        fscanf( fp, "%lf%lf", &Nodes[k].x, &Nodes[k].y );
        k++;  //increment k with 1
    }
    fclose( fp );  //every file opened must be closed

    getchar(); //this will stop the window so you can see the results
    return 0; //note that the function main must return always an integer
              //if the program completed successfully then the return value should be 0 ( zero )
}


Read the comments to understand what I have done. Note that you should have a file with the name "Node.data" ( without the quotes of course ) in the same folder as your .c file for the program to work.

Was this post helpful ? :) -->
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1