By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,415 Members | 1,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,415 IT Pros & Developers. It's quick & easy.

use template classes or standard classes and/or linked list

P: 8
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
Jun 2 '07 #1
Share this Question
Share on Google+
12 Replies


Savage
Expert 100+
P: 1,764
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
Jun 2 '07 #2

P: 8
Thank you for your answer
Jun 2 '07 #3

Savage
Expert 100+
P: 1,764
Thank you for your answer
Glad to help!

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

:)

Savage
Jun 2 '07 #4

P: 55
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,

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
Jun 2 '07 #5

P: 8
Thanks

I will trying to solve it by using classes and linklist

I'm using Microsoft visual studio.Net
Jun 3 '07 #6

P: 8
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3. #include<conio.h>
  4. #include <fstream>
  5. using namespace std;
  6. ofstream outfile ("Student_Records.txt");
  7.  
  8. class Student
  9. {
  10.     private:
  11.         string studName;
  12.         string studMajor;
  13.         float studGrade;
  14.     public:
  15.         int id;
  16.         void getStudent()
  17.             {
  18.                 cout<<"Enter student name: ";
  19.                 cin>>studName;
  20.                 cout<<"Enter student major: ";
  21.                 cin>>studMajor;
  22.                 cout<<"Enter student grade: ";
  23.                 cin>>studGrade;
  24.                 cout<<"Enter student ID: ";
  25.                 cin>>id;
  26.             }
  27.         void showStudent()
  28.             {
  29.                 cout<<"\tName :"<<studName<<endl;
  30.                 cout<<"\tMajor :"<<studMajor<<endl;
  31.                 cout<<"\tGrade :"<<studGrade<<endl;
  32.                 cout<<"\tID :"<<id<<endl;
  33.             }
  34. };
  35. struct Link
  36. {
  37.     Student stud;
  38.     Link* next;
  39. };
  40. class LinkList
  41. {
  42. private:
  43.     Link* head;
  44. public:
  45.     LinkList()
  46.         {
  47.         head=NULL;
  48.         }
  49.     void insert(Student s);
  50.     void show();
  51.     void update(Student &s);
  52.     void deletestudent();
  53.     void save();
  54.     void search();
  55. };
  56. void LinkList::insert(Student s)
  57. {
  58.     Link* newLink= new Link;
  59.     newLink->stud=s;
  60.     newLink->next=head;
  61.     head=newLink;
  62. }
  63. void LinkList::show()
  64. {
  65.     Link*current=head;
  66.     cout<<"Student Information List"<<endl;
  67.     while(current != NULL)
  68.     {
  69.     current->stud.showStudent();
  70.     current=current->next;
  71.     cout<<endl;
  72.     }
  73. }
  74. void LinkList::update(&)
  75. {
  76.  
  77. }
  78. void LinkList::search(int id)
  79. {
  80.     Link*current=head;
  81.     while(current!= NULL)
  82.     {
  83.         if(current->id == id)
  84.             return * current;
  85.         current=current->next;
  86.     }
  87.     return NULL;
  88. }
  89. void LinkList::deletestudent()
  90. {
  91. Link* current=search();
  92.     if(current ==NULL)
  93.         cout<<"\nThis student is not in the list\n";
  94.     else
  95.     {
  96.         if(current == head)
  97.         {
  98.             head=current->next;
  99.             delete current;
  100.         }
  101.         else
  102.         {
  103.         Link* previous=head;
  104.         while(previous !=NULL)
  105.         {
  106.             if(previous->next==current)
  107.             {
  108.                 previous->next=current->next;
  109.                 delete current;
  110.             }
  111.             previous=previous->next;
  112.         }
  113.         }
  114.     }
  115. }
  116. void LinkList::save()
  117. {
  118.  
  119. }
  120.  
  121.  
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
Jun 5 '07 #7

Savage
Expert 100+
P: 1,764
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
Jun 5 '07 #8

weaknessforcats
Expert Mod 5K+
P: 9,197
Is there some reason why you are doing this:

Expand|Select|Wrap|Line Numbers
  1. struct Link
  2. {
  3.     Student stud;
  4.     Link* next;
  5. };
  6. class LinkList
  7. {
  8. private:
  9.     Link* head;
  10. public:
  11.     LinkList()
  12.         {
  13.         head=NULL;
  14.         }
  15.     void insert(Student s);
  16.     void show();
  17.     void update(Student &s);
  18.     void deletestudent();
  19.     void save();
  20.     void search();
  21. };
  22.  
???

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:

Expand|Select|Wrap|Line Numbers
  1. list<Student> thelist;
  2.  
  3. Student  s(...args...);
  4.  
  5. thelist.push_back(s);
  6.  
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.
Jun 5 '07 #9

P: 8
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
Jun 6 '07 #10

weaknessforcats
Expert Mod 5K+
P: 9,197
And you are not allowed ot use the STL list template??
Jun 6 '07 #11

P: 8
for what i use STL?
I don't no how to save and update student records?
Jun 6 '07 #12

weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Jun 6 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.