use template classes or standard classes and/or linked list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • salohi
    New Member
    • Oct 2006
    • 8

    use template classes or standard classes and/or linked list

    hi

    i have question

    I dont need the code i just want to know from where i can start my solution ( a hit to what i use to solve)

    recording students and use files to save students details the program do insert, update , delete , save, show and search by index , name , character and other.

    should i use template classes or just classes
    and i use linklist or not
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by salohi
    hi

    i have question

    I dont need the code i just want to know from where i can start my solution ( a hit to what i use to solve)

    recording students and use files to save students details the program do insert, update , delete , save, show and search by index , name , character and other.

    should i use template classes or just classes
    and i use linklist or not
    I would use linked list and standard classes.

    Savage

    Comment

    • salohi
      New Member
      • Oct 2006
      • 8

      #3
      Thank you for your answer

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        Originally posted by salohi
        Thank you for your answer
        Glad to help!

        If u have some problems with coding please make us know.

        :)

        Savage

        Comment

        • thefarmer
          New Member
          • Nov 2006
          • 55

          #5
          hi there,

          actually you can use either ways, but find codes that it may feel you comfortable to use, if i were writing your program data stuctures are more convinient like struct.

          regards,

          Originally posted by salohi
          hi

          i have question

          I dont need the code i just want to know from where i can start my solution ( a hit to what i use to solve)

          recording students and use files to save students details the program do insert, update , delete , save, show and search by index , name , character and other.

          should i use template classes or just classes
          and i use linklist or not

          Comment

          • salohi
            New Member
            • Oct 2006
            • 8

            #6
            Thanks

            I will trying to solve it by using classes and linklist

            I'm using Microsoft visual studio.Net

            Comment

            • salohi
              New Member
              • Oct 2006
              • 8

              #7
              [code=cpp]
              #include<iostre am>
              #include<string >
              #include<conio. h>
              #include <fstream>
              using namespace std;
              ofstream outfile ("Student_Recor ds.txt");

              class Student
              {
              private:
              string studName;
              string studMajor;
              float studGrade;
              public:
              int id;
              void getStudent()
              {
              cout<<"Enter student name: ";
              cin>>studName;
              cout<<"Enter student major: ";
              cin>>studMajor;
              cout<<"Enter student grade: ";
              cin>>studGrade;
              cout<<"Enter student ID: ";
              cin>>id;
              }
              void showStudent()
              {
              cout<<"\tName :"<<studName<<e ndl;
              cout<<"\tMajor :"<<studMajor<< endl;
              cout<<"\tGrade :"<<studGrade<< endl;
              cout<<"\tID :"<<id<<endl ;
              }
              };
              struct Link
              {
              Student stud;
              Link* next;
              };
              class LinkList
              {
              private:
              Link* head;
              public:
              LinkList()
              {
              head=NULL;
              }
              void insert(Student s);
              void show();
              void update(Student &s);
              void deletestudent() ;
              void save();
              void search();
              };
              void LinkList::inser t(Student s)
              {
              Link* newLink= new Link;
              newLink->stud=s;
              newLink->next=head;
              head=newLink;
              }
              void LinkList::show( )
              {
              Link*current=he ad;
              cout<<"Student Information List"<<endl;
              while(current != NULL)
              {
              current->stud.showStude nt();
              current=current->next;
              cout<<endl;
              }
              }
              void LinkList::updat e(&)
              {

              }
              void LinkList::searc h(int id)
              {
              Link*current=he ad;
              while(current!= NULL)
              {
              if(current->id == id)
              return * current;
              current=current->next;
              }
              return NULL;
              }
              void LinkList::delet estudent()
              {
              Link* current=search( );
              if(current ==NULL)
              cout<<"\nThis student is not in the list\n";
              else
              {
              if(current == head)
              {
              head=current->next;
              delete current;
              }
              else
              {
              Link* previous=head;
              while(previous !=NULL)
              {
              if(previous->next==curren t)
              {
              previous->next=current->next;
              delete current;
              }
              previous=previo us->next;
              }
              }
              }
              }
              void LinkList::save( )
              {

              }

              [/code]
              I dont no how to save the student information by using files and how to do the update
              Please, can anyone help me in my cod
              Last edited by Niheel; Jun 5 '07, 09:38 AM. Reason: didn't use code tags

              Comment

              • Savage
                Recognized Expert Top Contributor
                • Feb 2007
                • 1759

                #8
                Create a pointer to the first element in list,output data to file,move the pointer to the next element and so on until reaching end of the list.

                Savage

                Comment

                • weaknessforcats
                  Recognized Expert Expert
                  • Mar 2007
                  • 9214

                  #9
                  Is there some reason why you are doing this:

                  [code=cpp]
                  struct Link
                  {
                  Student stud;
                  Link* next;
                  };
                  class LinkList
                  {
                  private:
                  Link* head;
                  public:
                  LinkList()
                  {
                  head=NULL;
                  }
                  void insert(Student s);
                  void show();
                  void update(Student &s);
                  void deletestudent() ;
                  void save();
                  void search();
                  };
                  [/code]

                  ???

                  Are you in some kind of computer science class where you need to write a linked list??

                  If the answer is no, then you should use the C++ Standard Library linked list:

                  [code=cpp]
                  list<Student> thelist;

                  Student s(...args...);

                  thelist.push_ba ck(s);
                  [/code]

                  and you be done.

                  If the answer is yes, and you need to write a linked list from scrach, then make it independent from Student so you have a chance to reuse the code again in another problem.

                  Comment

                  • salohi
                    New Member
                    • Oct 2006
                    • 8

                    #10
                    Are you in some kind of computer science class where you need to write a linked list??

                    Yes, Iam computer science student and i have to use the linklist and using files to save the student records

                    Comment

                    • weaknessforcats
                      Recognized Expert Expert
                      • Mar 2007
                      • 9214

                      #11
                      And you are not allowed ot use the STL list template??

                      Comment

                      • salohi
                        New Member
                        • Oct 2006
                        • 8

                        #12
                        for what i use STL?
                        I don't no how to save and update student records?

                        Comment

                        • weaknessforcats
                          Recognized Expert Expert
                          • Mar 2007
                          • 9214

                          #13
                          You use the STL to create a container to for your Students.

                          Then you put the Student objects in the container.

                          Once to can put the Student objects in the container and also be able to display them while they are in the container, then yout can start thinking about disc files.

                          But a disc file with 10 Students in it is no good if, when you read the file, you have no place to put the data.

                          You spend your time writing code for the Students. You spend NO time writing code to put the Students in a linked list or some such thing. The container has already been written for you. I guarantee by the time you learn how to operate the STL linked list, the linked list you code will still not be working.

                          Comment

                          Working...