Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > Other Topics > Computer Technical Help
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #11  
Old 09-15-2007, 06:53 PM
IRuleYouHard IRuleYouHard is offline
Senior Member
 
Join Date: Nov 2006
Location: MS Paint Forum.
Posts: 1,050
Default Re: C Programming Halp! :)

[ QUOTE ]
1. that is really [censored] ugly
2. do you really comment every [censored] line?
3. send it this [censored] ARRAY_LIST *plist, YEAR targetYear, int *loc

[/ QUOTE ]
1. This is the problem I'm having... the professor created this and told us to use it... I could make my own but thats not allowed.
2. HELL NO
3. Well I'm not sure what those are. [img]/images/graemlins/smile.gif[/img]

I'm supposed to use data from a .data file and send it to this function...but don't know what the first and last ones are...
[img]/images/graemlins/frown.gif[/img]
Reply With Quote
  #12  
Old 09-15-2007, 07:37 PM
LeapFrog LeapFrog is offline
Senior Member
 
Join Date: Oct 2006
Location: Mystery time!
Posts: 1,173
Default Re: C Programming Halp! :)

[ QUOTE ]

3. Well I'm not sure what those are.


[/ QUOTE ]
Uh, read whatever intro to comp programming book you should have read? There are also plenty of webpages on the 'intertubes' that have programming examples, docs, etc. Anyone helping you with this is just putting a band aid on a gangrenous leg...

edit: this was not meant to sound unduly harsh. If you don't know the requirements then talk to your prof. Then read basic programming book, then perhaps come back and ask a thoughtful question. As in a general, not specific to your homework assignment question. [img]/images/graemlins/smile.gif[/img]

Reply With Quote
  #13  
Old 09-15-2007, 07:37 PM
usha usha is offline
Senior Member
 
Join Date: Jan 2007
Location: Kickapoo
Posts: 225
Default Re: C Programming Halp! :)

[x] OP is going to fail.
Reply With Quote
  #14  
Old 09-15-2007, 07:46 PM
LeapFrog LeapFrog is offline
Senior Member
 
Join Date: Oct 2006
Location: Mystery time!
Posts: 1,173
Default Re: C Programming Halp! :)

hmm, some sort of double post when trying to edit.
Reply With Quote
  #15  
Old 09-15-2007, 08:05 PM
IRuleYouHard IRuleYouHard is offline
Senior Member
 
Join Date: Nov 2006
Location: MS Paint Forum.
Posts: 1,050
Default Re: C Programming Halp! :)

$20 on tilt to anyone who helps me finish this thing. I'm just plain stupid I guess.
Reply With Quote
  #16  
Old 09-15-2007, 08:42 PM
_dave_ _dave_ is offline
Senior Member
 
Join Date: Feb 2005
Location: UK
Posts: 2,628
Default Re: C Programming Halp! :)

[ QUOTE ]

I'm supposed to use data from a .data file and send it to this function...but don't know what the first and last ones are...


[/ QUOTE ]

They are pointers IIRC.

Seriously, follow Leapfrog's advice and (re)read the documentation recommended for your course.
Reply With Quote
  #17  
Old 09-15-2007, 09:18 PM
frinxor frinxor is offline
Senior Member
 
Join Date: Dec 2006
Location: santa barbara
Posts: 144
Default Re: C Programming Halp! :)

you're trying to print out every car in the .data file that has the same year as the year you're searching for.

somehow, you're going to need to get all the cars into an arraylist (not in this function), and then call this function when you want to print out all the cars with a specific year.

plist is going to be the array with all the cars, targetYear is the year that you're going to be searching for, loc is going to be the location (index in plist) of the last car found with targetYear. (you can pass for example a loc=-1 value and if no cars are found, loc will remain -1, otherwise the last car with the targetYear found's location will be the new loc after you run the program).
Reply With Quote
  #18  
Old 09-15-2007, 09:20 PM
frinxor frinxor is offline
Senior Member
 
Join Date: Dec 2006
Location: santa barbara
Posts: 144
Default Re: C Programming Halp! :)

btw, plist holds an array of "car". if your professor hasnt given you the skeleton for that class or the function to get the array list from the .data file, you have a long way to go
Reply With Quote
  #19  
Old 09-15-2007, 10:58 PM
CORed CORed is offline
Senior Member
 
Join Date: Sep 2002
Posts: 4,798
Default Re: C Programming Halp! :)

[ QUOTE ]
btw, plist holds an array of "car". if your professor hasnt given you the skeleton for that class or the function to get the array list from the .data file, you have a long way to go

[/ QUOTE ]

I know I'm nit-picking hear, but it's C, not C++ or Java, so "car" would be a structure, not a class.
Reply With Quote
  #20  
Old 09-16-2007, 08:55 AM
fiskebent fiskebent is offline
Senior Member
 
Join Date: Nov 2005
Location: To your right
Posts: 1,124
Default Re: C Programming Halp! :)

<font class="small">Code:</font><hr /><pre>
#define YEAR int
#define EQ(a, b) ((a) == (b))

typedef struct {
char make[50];
char model[50];
YEAR year;
} CAR;

typedef struct {
int count;
CAR car[20];
} ARRAY_LIST;

typedef enum boolean
{FALSE, TRUE}
BOOLEAN;

ARRAY_LIST carlist = {5,
{ {"Dodge", "Dodge model", 1985},
{"Chevrolet", "Chevrolet model", 1990},
{"Cadillac", "Cadillac model", 2000},
{"BMW", "M5", 2003},
{"Porsche", "Carrera", 2007}
}
};

BOOLEAN SequentialSearch(ARRAY_LIST *plist, YEAR targetYear, int *loc)
{
int i; /* loop control variable */
int numFound; /* counts how many found */
BOOLEAN found; /* return value TRUE if success FALSE if not */

numFound = 0; /* set to none in the beginning */
found = FALSE; /* initial setting until a record is found */

/* search through the array list for targets */
for(i = 0; i &lt; plist-&gt;count; i++)
{
if (EQ(targetYear, plist-&gt;car[i].year)) /* target year is found */
{
loc = loc;
numFound++; /* add one to the count */

/* ********
HERE IS WHERE YOU WILL WANT TO HANDLE DISPLAYING THE CAR RECORD.
EITHER DIRECTLY, OR BY CALLING A FUNCTION TO DO IT
********* */
printf("%s - %s - %d\n", plist-&gt;car[i].make, plist-&gt;car[i].model, plist-&gt;car[i].year);

found = TRUE; /* successfully found at least one record */

}
}
printf("\n\n %d record(s) found that match\n", numFound);
i = 0; /* reset value of i */
return found;
}

void main()
{
BOOLEAN found;
int loc;
found = SequentialSearch(&amp;carlist, 2007, &amp;loc);
}
</pre><hr />

Try to understand what the code does before you hand it in [img]/images/graemlins/smile.gif[/img]
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:16 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.