473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

use template classes or standard classes and/or linked list

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
12 2375
Savage
1,764 Expert 1GB
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
salohi
8
Thank you for your answer
Jun 2 '07 #3
Savage
1,764 Expert 1GB
Thank you for your answer
Glad to help!

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

:)

Savage
Jun 2 '07 #4
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
salohi
8
Thanks

I will trying to solve it by using classes and linklist

I'm using Microsoft visual studio.Net
Jun 3 '07 #6
salohi
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
1,764 Expert 1GB
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
9,208 Expert Mod 8TB
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
salohi
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
9,208 Expert Mod 8TB
And you are not allowed ot use the STL list template??
Jun 6 '07 #11
salohi
8
for what i use STL?
I don't no how to save and update student records?
Jun 6 '07 #12
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

7
by: Woodster | last post by:
Further to a question I posted here recently about coding an xml rpeort parser, I need to use a list of name/value pairs, in this case, a list property names and values for a given tag. Rather...
1
by: Greg Phillips | last post by:
Hello everyone, I have read the section on templates in The C++ Programming Language 3rd edition 3 times over the last 4 days. Still I am stumped. I'll explain a bit about what I am doing...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
4
by: Mikhail N. Kupchik | last post by:
Hi All. I have a question regarding C++ programming language standard. It is related to standard library, not to the core language. Is it portable to instantiate template class std::list<>...
5
by: Johan | last post by:
Hi, Hi like to create a linked list with a template class ( see below ). How to make one using the STL container list. I want to create a linked list with different kind of types i.e....
5
by: Mark Stijnman | last post by:
I am trying to teach myself template metaprogramming and I have been trying to create lists of related types. I am however stuck when I want to make a template that gives me the last type in a...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.