Question:
guyz..plz help me with this C program based on structures..?
saylee p
2006-11-03 06:58:24 UTC
i m in the first yr of engg. n i need to submit this pgm this monday..so plz plz help..create a program to declare the structure for students which will store 5 records (name & roll number) and sort the records in ascending order of their roll numbers.
Five answers:
alakit013
2006-11-03 19:53:25 UTC
Plain C:



#include

#include

#include

#include

#include





void pause( void )

{

while( !kbhit())

;

getch();

}



struct _str

{

char name [32] ;

int rn; // roll number

};



void test_fill( _str data[], int n )

{

srand( time(0));

for( int i = 0; i < n; i++ )

{

sprintf( data[i].name, "Student # %d", i+1 );

data[i].rn = rand();

}

}



int compare_struct( const void * p1, const void * p2 )

{

const _str *s1, *s2;

s1 = (const _str*)p1;

s2 = (const _str*)p2;

if( s1->rn < s2->rn )

return -1;

if( s1->rn > s2->rn )

return 1;

return 0;

}



void print_str( _str data[], int n )

{

for( int i = 0; i < n; i++ )

printf( "%6d: %s\n", data[i].rn, data[i].name);

}



#define DATA_SIZE 6



int main( int ac, char ** av )

{

_str data[DATA_SIZE];

test_fill( data, DATA_SIZE );

printf( "Generating data:\n" );

print_str( data, DATA_SIZE );

printf( "Sorting:\n" );

qsort( &data[0], DATA_SIZE, sizeof( _str ), compare_struct );

print_str( data, DATA_SIZE );

pause();

return 0;

}
mcubea
2006-11-03 07:22:55 UTC
I won't give you full solution but some hints

1. Create a structure that will have name (stored as string) and roll number (stored as int)

2. Create a link list.

3. Inside the main program, iterate to take inputs from user name and roll number

4. Keep on adding these to new structure and add the structure to link list

5. Once user input is done

6. Iterate over the link list, and keep on getting the roll number. Store in array.

7. Write an algorithm to sort this number and get the indices in array in increasing order of roll number

8. With the indices you know in which order the structure in link list is stored. Query from link list these structures as per sorted indices and display to user.



Give it a try, you will learn something. Ready made solution wont teach you anything
?
2016-12-09 06:51:05 UTC
the least confusing programming language to examine actual relies upon on you and what you decide directly to examine for. Programming is a reasonably stressful interest requiring concentration, self-discipline, the flexibility to make and execute a plan, interest to element and persistence. that's not suitable which language you're using none of them will take any of those calls for away. I hate answering a question with a question, yet what's it you decide directly to do inclusive of your application? Then enable that instruction manual you to the main suitable language for you. studying the 1st language is the toughest, by way of the time you come back to the 5th or the 6th you have got lots journey from the different languages that the ameliorations do no longer seem so great any further. The debates on the advantages of diverse languages have been on the internet when you consider that its inception. the version between an interpreted language and a compiled language are negligible many of the time and for a beginner i may be tempted just to overlook approximately it. For internet programming try something like Hypertext Preprocessor. you are able to blend HTML and Hypertext Preprocessor particularly with ease on the website and you will get a fulfilling effect particularly without delay. For an utility my own decision may be the two Java or Python. They the two have their ardent advocates and, extra effective yet, they the two have great libraries of code which could help you get what you decide on. For textual content textile processing that's confusing to beat Perl, even nevertheless it may turn around and chew you at circumstances. For video games the two Java or C#, yet be warned i do no longer think of that anybody on right here might call C uncomplicated for an entire beginner. For a compiler, working gadget, real-time programming or a computationally confusing activity, C# or C++ is the only sport on the city, yet your first few classes would have loads of debugging time linked. in case you do no longer fairly be responsive to what you decide directly to do with this gadget then probable Python or Java are your maximum suitable bets. they're the two useful languages and that they gained't bathroom you down with memory administration or complicated pointer stuff, they're the two particularly readable without too lots unusual-looking punctuation marks and as I reported they have great libraries which could help with tremendously much something you are able to think of of.
anonymous
2006-11-03 07:04:30 UTC
I'm not a C user. But you can use Pseudocode to plan what you want to happen in English the translate it into C.



So you'll need an input screen to get student information. You'll then need to be able to store it (and possible verify it).



A list of all stored files. If you save them in one directory you can either have a student per file or all students in one file. The first will be to use but will create more files(not a problem for small scale applications). You'll need to sort this list. The only type of sorting I remember is bubble sort, but i don't think it applies here(though it could be used).



Good luck.
Prashant Rana
2006-11-03 17:21:20 UTC
I am a best teacher of C programming Language and data structure so what ever help you need you can ask with me my e-mail prashant.rana@rediffmail.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...