URGENT: Help wanted...in C

This is a discussion on URGENT: Help wanted...in C within the C Programming forums, part of the General Programming Boards category; hi ther, I need a help in my C assignment, which is to be submitted tommorrow. I am attaching the ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    3

    Question URGENT: Help wanted...in C

    hi ther,

    I need a help in my C assignment, which is to be submitted tommorrow. I am attaching the question along with this. I am in a desperate situation, as i m very new to C. I m looking forward to hear from u ASAP...V have to run this program on unix platform only, and no C++ COMMANDS shud b used....thnx a lot


    here is the question(it can b viewed in the attachment also):


    Implement a menu driven library catalogue system that allows users to perform various catalogue maintenance tasks. You are only allowed to use the C programming language. You are not allowed to use C++.

    Please do not use global variables. Up to 50% of marks will be lost for assignments that use global variables.

    Please use dynamic memory allocation to store student record information. Up to 50% of marks will be lost for assignments that do not use dynamic memory allocation to store student record information.

    Please do functional decomposition. Up to 50% of marks will be lost for students who try to write the entire program in one main function or something similar. There should be at least 5 functions for the assignment. One function for each task 2 to 4. Two functions for task 5. More functions than 5 is highly recommended. The aim of this rule is to teach you how to pass pointer arguments into functions.

    The assignment has been broken up into 5 tasks.

    Task 1 [10 marks code correctness]

    The program should be menu driven. The user should be presented with the following menu:

    1. Load catalogue from file
    2. Delete book from catalogue
    3. Save catalogue to file
    4. Sort and display catalogue
    5. Quit

    After selecting one of the above options the corresponding task should be performed. After completing the selected task, the menu should be displayed again for the user to choose from again.


    Task 2 [20 marks code correctness]

    Implement the load catalogue from file menu option. After selecting this option the user should be asked to enter the name of a file to be loaded. The file should then be loaded into a run-time(dynamically) allocated data structure. You should not use compile-time (static) memory allocation. You can assume the file will have the following format.


    [Number of books]
    [Title of book]
    [Author first name], [Author surname]
    [Year of publication]
    [Replacement cost]


    [Title of book]
    [Author first name], [Author surname]
    [Year of publication]
    [Replacement cost]


    The stands for intermediate catalogue entries.

    Here is an explanation of the above fields:

    [Number of books] - This is the number of book entries stored in the file

    [Title of book] A string specifying the title of the book, the string may contain spaces.

    [Author First name], [Author Surname] Two strings which do not contain spaces but
    are separated by a comma followed by a space.

    [Year of publication] - A number specifying the year that the book was published

    [Replacement cost] - Cost of replacing a book, it may contain a decimal point.


    Below is an example of a catalogue file that contains 2 books:

    2
    C for beginners
    Peter, Kernighan
    1999
    102.5
    XML data Management
    Amit, Chandhri
    2005
    122.3






    Task 3 [15 marks code correctness]

    Implement the delete book from catalogue menu option. After selecting this option the user should be asked to specify the book to be deleted using the following sub-menu:

    1. Specify book title
    2. Specify author first name
    3. Specify author last name

    After choosing one of the above sub-menu options, the user should be asked to type in a string to be used for finding the book to be deleted. Note the string has to completely match the book attribute. Partial match is not considered a match.



    In the following example the user strings does not match the corresponding books:

    User types in for book title: Cforbeginners
    Actual book title: C for beginners

    User types in for author first name: peters
    Actual book author first name: peter

    User types in for author surname: peter
    Actual book author surname: peterson

    The search should be case insensitive. Therefore the following does match:

    User types in for author first name: peter
    Actual book author first name: peTer

    User types in for book title: c for beginners
    Actual book title: C For Beginners


    If more than one matching book is found then all matching books are deleted. The program needs to free up memory that is no longer needed as a result of the deletion.







    Task 4 [10 marks code correctness]

    Implement the save catalogue to file menu option. After selecting this option the user should be asked to specify the name of the save file. All the book catalogue data should be stored onto the specified file in the same format as the file loaded in Task 2.


    Task 5 [20 marks code correctness]

    Implement the sort and display catalogue menu option. Once this option is selected the following sub-menu is displayed:

    1. Sort books by title
    2. Sort books by surname
    3. Sort books by replacement cost
    4. Sort books by year of publication

    To get full marks for this task you should design your sorting algorithm so that it uses function pointers to allow the same algorithm implementation to be used to sort for all 4 different attributes.

    After the above choice is made the books are sorted in ascending order and all the books attributes are displayed as follows:

    Number of books in catalogue = [number of books]
    ---------------------------------------------------------------
    Title: [title of book]
    Author: [first name of author] [surname of author]
    Year of publication: [year of publication]
    Replacement cost: $[cost of replacement]
    ---------------------------------------------------------------
    ....
    ....
    ---------------------------------------------------------------
    Title: [title of book]
    Author: [first name of author] [surname of author]
    Year of publication: [year of publication]
    Replacement cost: $[cost of replacement]
    ---------------------------------------------------------------

    Note: [title of book] [first name of author] [surname of author] [year of publication]
    [cost of replacement] have the same meaning as those for task 2.

    Here is an example output:

    Number of books in catalogue = 2
    ---------------------------------------------------------------
    Title: C for beginners
    Author: Peter Smith
    Year of publication: 1999
    Replacement cost: $102.50
    ---------------------------------------------------------------
    Title: Java programmers hand book
    Author: John Edwards
    Year of publication: 2003
    Replacement cost: $105.2
    ---------------------------------------------------------------
    Attached Files Attached Files

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Read the damn rules. No one is going to do your homework for you.

    * waits for MacGyver *

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by zacs7 View Post
    * waits for MacGyver *
    It's nice to be loved.

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    At least make some kind of effort. Start with

    Code:
    #include <stdio.h>
    
    int main ( void )
    {
       getchar();
    
       return 0;
    }
    Fair comments guys ^^
    I'm just trying to be a better person - My Name Is Earl

  5. #5
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by iamjimjohn View Post
    hi ther,
    Hi, but my name's not Ther.

    Quote Originally Posted by iamjimjohn
    here is the question(it can b viewed in the attachment also):
    Where's the question? Is there something you don't understand how to do?
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    We could blast him some more, like with the tutorial on how to ask questions. Or perhaps we could sit here and tell him stories about how back in our day, we had to code in machine code by hand on magnetic tape with a tiny, tiny magnetic pencil, and fit our entire assignment in one megabyte. Compiling would take the entire semester, so we would have had to get it right in the first week of classes or else we would fail the final....

    Or we could just wait for him to respond with more information and a try of his own.

  7. #7
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    A whole megabyte??!!! They don't make nostalgia like they used to.
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Unless you're an experienced programmer in C, you will not complete this assignment, imo.

    The requirements are reasonable, but numerous, and the coding is not trivial.

    We'll be glad to help answer questions or problems with code you submit, but we're not a homework forum.

    It's too bad that you only have such a short time before it's due. This is a very worthwhile assignment, and worthy of more time. Lots to be learned from this.

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    So why didnt he/she post this like three weeks ago or whenever the assignment was handed out? By this time we could of helped the assignment would be done by now or more or less finished
    I'm just trying to be a better person - My Name Is Earl

  10. #10
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    *wonders if he's tried posting it on another forum yet *

    Tip: Stop wasting your time, and get programming (unless you don't want sleep).

  11. #11
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Apparently he's got classmates:

    http://www.ozzu.com/ftopic77047.html
    http://www.rentacoder.com/RentACoder...questId=682833

    And for the rest: http://www.google.com/search?rls=en&...utf-8&oe=utf-8

    This is shameful. Can't say I would feel too sorry if the professor found out about some of these people.
    Last edited by MacGyver; 05-18-2007 at 02:00 AM.

  12. #12
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Yea but even they did how could they prove it? There is no way the student will tell the professor "oh he or she did this entire assignment for me"
    I'm just trying to be a better person - My Name Is Earl

  13. #13
    Registered User
    Join Date
    May 2007
    Posts
    3

    Question hey guys

    i tried it out guys.....these files n pointers r givin me a headache....cud u c to wat i have written?....plz help....this is my third day of no sleeping

  14. #14
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Well help us to help you, Post what you have done so we can look at it and tell us where it is going wrong
    I'm just trying to be a better person - My Name Is Earl

  15. #15
    Registered User
    Join Date
    May 2007
    Posts
    3

    Question Plzz....guys

    This is the code i wrote...plz make it work for me
    Code:
    /* System-wide header files. */
    #include "assignment2.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    int loadData(char* menuFile);
    void printList(bookType *list);
    
    int main()
    {
    	
    /* To store the user's input. 2 extra spaces are needed for the '\n' and
          '\0' */
       char input[6];
       int inputNumber = 0, inputLength = 0; 
       
       /* To store the user's File input. 2 extra spaces are needed for the '\n' and
       '\0' */
       char fileInput[18];
       
          
       do
       {
          /* Print out menu */
          printf("\nMain Menu:\n");
          printf(" 1. Load catalogue from file\n");
          printf(" 2. Delete book from catalogue\n");
          printf(" 3. Save catalogue to file\n");
          printf(" 4. Sort and display catalogue\n");
          printf(" 5. Quit\n");
          printf("\nSelect your option (1-5): ");
    
          /* Store user's input and check for correct length */
    	      
    
    	fgets(input, 7, stdin);
    
             /* Convert the user's input into an integer */
             inputNumber = atoi(input);
    
             /* Process the user's request */
             if(inputNumber == 1)
             {
    	 	printf("Please enter the name of the File: ");
    		
    		/* Retrieve User Input. */
    		if(fgets (fileInput, 20, stdin)) 
    		{
    	
    		      /*************************************************
    		       * The Value is OK, Replace the Trailing New Line
    		       * with the Empty Character.
    		       ************************************************/
    		      inputLength = strlen(fileInput);
    	 
    		      if (fileInput[inputLength - 1] == '\n')
          		      {
    		         fileInput[inputLength-1] ='\0';	
          		      }
        		}
    		
    		loadData(fileInput);
    	 }
    
             else if(inputNumber == 2)
               {}
    
             else if(inputNumber == 3)
                {printf("Hello3\n");}
    
             else if(inputNumber == 4)
                {printf("Hello4\n");}
    
             else if(inputNumber == 5)
             {
                /* If user abort's program, free all allocated memory before
                   exiting */
                printf("Thank you for using this program. Now exiting...\n");
                return EXIT_SUCCESS;
             }
    
       }
    
       while(inputNumber != 5);
    
       return EXIT_SUCCESS;
    }
    
    /****************************************************************************
    * Loads all data into the system.
    ****************************************************************************/
    int loadData(char* menuFile)
    {
       FILE *fileload;
       char bookLine[40];
       bookTypePtr next;
       
       int line = 0;
      
       if ( (fileload=fopen(menuFile,"r"))==NULL)
       	{
       		printf("\nCannot open the specified file");
          }
          else{
          	printf ("\n File loaded successfully\n \n");
    	 
             while(fgets(bookLine, 30, fileload) != NULL)
    	 {
    	   next = (bookTypePtr)malloc(sizeof(struct book));
    	   
             switch(line)
    	 {
    	 	case 0: next->numItems = atoi(bookLine);
    			printf("%d\n",next->numItems); 
    			break;
    		case 1: strcpy(next->bookTitle, bookLine);
    			printf("%s\n",next->bookTitle);
    			break;
    		case 2: strcpy(next->authorFirstName, strtok(bookLine,
    		","));
    			strcpy(next->authorLastName, strtok(NULL, ""));
    			printf("%s\n",next->authorFirstName);
    			break;
    		case 3: next->year = atoi(bookLine);
    			printf("%d\n",next->year);
    			break;
    		case 4: next->repCost = atof(bookLine);
    			printf("%f\n",next->repCost);
    			break;
    			
    		case 5: next = next->nextBook;
    			line = 1;
    	 }
    	 
    	 line ++;
     	}
    	}
       fclose(fileload);
       return 0;
    }
    
    
    
    
    
    
    
    
    
    Header File
    
    * System-wide header files. */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    typedef struct book* bookTypePtr;
    
    /* Structure definitions. */
    typedef struct book
    {
       char bookTitle[30];
       char authorFirstName[30];
       char authorLastName[30];
    
       unsigned numItems;
       int year;
       float repCost;
       bookTypePtr nextBook;
       } bookType;
    
    /* End of file */

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent Help Needed In Writing Algorithm!!
    By Vikramnb in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2009, 11:46 AM
  2. Getting a message with wanted lparam from queue
    By BrownB in forum Windows Programming
    Replies: 6
    Last Post: 12-24-2007, 07:37 PM
  3. BitWise Newbie - Needs Urgent Help
    By frodonet in forum C Programming
    Replies: 15
    Last Post: 09-26-2007, 12:58 PM
  4. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM
  5. I just wanted....
    By ILoveVectors in forum C++ Programming
    Replies: 0
    Last Post: 06-22-2005, 09:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21