Thread: School Record

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    129

    School Record

    I want to write a C program that stores the records of student studying in school. I would like to take less memory to store record

    format for record

    Name :
    Class :
    Fees :
    Year :

    I think the structure will be used to store the data of different types

    Code:
    struct SCHOOL_RECORD 
    {
        char Name;
        int class;
        float fees;
        int year 
    };
    I do not know how many students are there in the school. I do not know how many class are there in the school.

    Do not consider this as school assignment. This is a question comes in mind when I am trying to write a big program

    When I think of writing the program, I do not understand what to use. I don't need program I just want an idea how to implement this in the program

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    A name would be a string, so it would not be a single char. The fees should use fixed point rather than floating point, so one approach is to store the quantity in cents instead of dollars (or whatever are the corresponding currency terms used in your country).

    You would presumably use dynamic memory allocation to store the lists of students and classes.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well the first thing is, you don't try and build the whole thing in one keyboard session, or even in one attempt.

    Code:
    #define MAX_NAMELEN  20
    #define MAX_CLASSES 5
    #define MAX_STUDENTS 100;
    struct student {
      char name[MAX_NAMELEN];
      int classes[MAX_CLASSES];
      int year;
      float fees;
    };
    You start with
    Code:
    struct student students[MAX_STUDENTS];

    Basically, you use the fixed sized arrays to make sure everything works within the constraints you've imposed.

    Later on, it's a small change which gets you to
    Code:
    struct student *students = malloc( num_students * sizeof(*students) );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2017
    Posts
    129
    Quote Originally Posted by laserlight View Post
    A name would be a string, so it would not be a single char. The fees should use fixed point rather than floating point, so one approach is to store the quantity in cents instead of dollars (or whatever are the corresponding currency terms used in your country).

    You would presumably use dynamic memory allocation to store the lists of students and classes.
    Thank you laserlight and salem

    okay So I made a list just to store student fees.

    Code:
    #include<stdio.h>#include<stdlib.h> 
         
    struct node{
      int Fees;
      struct node *next;
    };
       
    struct node* newNode(int college_fees, struct node *next) {
        struct node *new = malloc(sizeof(*new));
               new->Fees = college_fees;
               new->next = next;
        return new;
    }
       
    void show(struct node *head){
         struct node *c;
         c = head;
         while (c!=NULL){
               printf("%d dollar \n",c->Fees);
               c = c->next;
               }
        
         }
     
    
    
            
    int main (void ) {
       struct node *head = NULL;  
         
    head = newNode(10, head);
    head = newNode(20, head);
    head = newNode(30, head);
    head = newNode(40, head);
    head = newNode(50, head);
    head = newNode(60, head); 
     
    show(head);
    
    
            
     return 0;
    }
    60 dollar
    50 dollar
    40 dollar
    30 dollar
    20 dollar
    10 dollar

    why did you suggested dynamic memory allocation to store the lists of students and classes. instead of fixed size array?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > why did you suggested dynamic memory allocation to store the lists of students and classes. instead of fixed size array?
    A fixed sized array is simpler than a dynamically sized array.

    A dynamically sized array is simpler than a linked list.

    A linked list is simpler than a binary tree.

    You don't escalate the complexity too early or too quickly.
    Get the basics working and evolve.
    A development process

    If you go in right at the start all guns blazing, you just end up trying to solve too many problems at the same time and get nowhere in a hurry.

    Look, neither of these things gives a damn whether you just have one student, an array of students or a list of students.
    Code:
    void readStudent( struct student *s ) {
    }
    
    void printStudent( const struct student *s ) {
    }
    Make sure you can adequately solve the functional aspect of managing a single student first, then you can worry about how you store N of them.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by abhi143
    okay So I made a list just to store student fees.
    I don't understand why you would do that when nobody suggested that you use a linked list, and you haven't even determined if it makes sense to have a separate list of student fees, however that list might be represented. What's the point of asking at a conceptual level when you are itching to immediately jump in and do your own thing anyway?

    Quote Originally Posted by abhi143
    why did you suggested dynamic memory allocation to store the lists of students and classes. instead of fixed size array?
    That's because you wrote: "I do not know how many students are there in the school. I do not know how many class are there in the school." Since schools can vary in size from tiny private schools catering to a select group of students, to large international institutions, it makes sense to use dynamic memory allocation so as to avoid having to allocate a great deal of memory when you only need a small amount.

    But if you were actually trying to implement this, then you would do what Salem suggested: start with a fixed size array first so as to get things to work without having to deal with manual memory management plus the rest of what you're actually trying to do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,791
    I don't know why you'd even try this. Use a database, not C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Update Record & Delete Record in File.
    By unsafe_pilot1 in forum C Programming
    Replies: 13
    Last Post: 05-18-2008, 07:22 AM
  2. New record.
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 08-08-2004, 05:26 AM
  3. Record From TV
    By caroundw5h in forum Tech Board
    Replies: 4
    Last Post: 12-17-2003, 09:46 AM
  4. Get to First Record
    By Colin in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2002, 03:07 PM
  5. Set record
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-26-2001, 04:47 AM

Tags for this Thread