Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,951 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,667 people online right now. Registration is fast and FREE... Join Now!




student exmple

 
Reply to this topicStart new topic

student exmple, plz i need ur help i dunno wat da hell is wrong wid my prog

juju88
19 May, 2008 - 10:28 AM
Post #1

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 5

Given the sparse table that connects between s students and c courses and assigns a grade to each student in a course.
a)define a proper node for the above table.
b)define a class sparse table class, with proper data members and the following member functions
-function add student to a course
-function find number of courses taken by praticular student.
-function average of grades in a praticular course.
-function number of fail grades in particular course.
-function average of a student.





CODE

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class course
{
public:
    course(string z,int c)
    {
        Namecourse=z;
        Markcourse=c;
        next=NULL;


    }
    course()
    {next=NULL;    }
    string Namecourse;
    int Markcourse;
    course *next;
};
class Stundents :public course
{
public:
    int NoStundent;
    string NameStundent;
    Stundents *nextStundent;
    course *headcourses;
    course *tailcourses;
    Stundents(){
        nextStundent=NULL;
        headcourses=NULL;
        tailcourses=NULL;
    }
    Stundents(int x,string y,int a,string z[],int c[]){
    NoStundent=x;
    NameStundent =y;
    nextStundent=NULL;
    headcourses=NULL;
    tailcourses=NULL;
    
    
    for(int i=0;i<a;i++)
    {    
    if(tailcourses == NULL)
    {
        
        tailcourses =new course(z[i],c[i]);
        headcourses=tailcourses;
    }
    else
    {
        
        
        tailcourses->next=new course(z[i],c[i]);
        tailcourses=tailcourses->next;
    }}
    
}
};
class Opertors
{
private:
    Stundents *head;
    Stundents *tail;
public:
    Opertors()
    {
        head=NULL;
        tail=NULL;
    }
    void AddStudent();
    void Print();
    void SearchByNo(int x);
    void SearchByCourse(string x);

};
void main()
{
    Opertors n;
    int z;
    n.AddStudent();
    cout<<"Enter no.student : ";
    cin>>z;
    n.SearchByNo(z);
    string x;
    cout<<"Enter Course Name:"<<endl;
    cin>>x;
    n.SearchByCourse(x);

}
void Opertors::AddStudent()
{
    ifstream input;
    input.open("data.dat");
    int x;string y;int a;string z[20];int c[20];
    for(int i=0;i<3;i++)
    {
        
        input>>x>>y>>a;
        for(int j=0;j<a;j++)
        {
            input>>z[j];
            input>>c[j];

        }
                
        
    if(tail == NULL)
    {    
        tail=new Stundents(x,y,a,z,c);
        head=tail;
    }
    
    else
    {
        
        tail->nextStundent=new Stundents(x,y,a,z,c);
        tail=tail->nextStundent;

    }
    }
    

    input.close();

}
void Opertors::Print()
{
    Stundents *head1=head;
    while(head1 !=NULL)
    {
        cout<<head1->NoStundent<<" "<<head1->NameStundent<<" ";
        course *h2=head1->headcourses;
        while(h2!=NULL)
        {
            cout<<h2->Namecourse<<" "<<h2->Markcourse<<" ";
            h2=h2->next;

        }
        head1=head1->nextStundent;
        cout<<endl;

    }


}
void Opertors::SearchByNo(int x)
{
    Stundents *head1=head;
    while(head1 !=NULL)
    {
        if (head1->NoStundent == x)
        {
        cout<<head1->NoStundent<<" "<<head1->NameStundent<<" ";
        course *h2=head1->headcourses;
        while(h2!=NULL)
        {
            cout<<h2->Namecourse<<" "<<h2->Markcourse<<" ";
            h2=h2->next;

        }
        
        cout<<endl;
        break;
        }
        head1=head1->nextStundent;

    }

}
void Opertors::SearchByCourse(string x)
{
    Stundents *head1=head;
    while(head1 !=NULL)
    {
        course *h2=head1->headcourses;
        while(h2 != NULL)
        {
            if(x == h2->Namecourse)
                cout<<head1->NameStundent<<"   "<<h2->Markcourse<<endl;
            h2=h2->next;

        }
        head1=head1->nextStundent;
    }

}



User is offlineProfile CardPM
+Quote Post

juju88
RE: Student Exmple
19 May, 2008 - 10:37 AM
Post #2

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 5

guys plz help me sad.gifsad.gif
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Student Exmple
19 May, 2008 - 10:39 AM
Post #3

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 14,921



Thanked: 47 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
You're gonna have to wait a little more than 9 minutes.

If it's THAT urgent, you can click the "Live Help" link on the right. It'll cost you a couple $$ but you can chat with someone live.


User is online!Profile CardPM
+Quote Post

Cerolobo
RE: Student Exmple
19 May, 2008 - 10:39 AM
Post #4

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
Before you posted, you should have seen a big yellow box that says
QUOTE
1. Are you sure this is the right forum for this post? (No Programming Questions in Introduce Yourself or the Caffeine Lounge)
2. You must show your code before receiving help. We won't do your homework for you.
3. Use BBCode when posting. For example:
CODE
Paste Your Code Here

4. Give your topic a descriptive title, NOT "Help" or "Plz Help Me" or "I'm a noob"
5. Describe any errors you are encountering. Help us help you!
6. Please spell-check your entire post.


With that being said, you did not follow number 4, 5, or 6.

We need more information then just
QUOTE
student exmple, plz i need ur help i dunno wat da hell is wrong wid my prog

For example, does the program actually compile? Where there any warnings or errors? If so, what were they? Is you program crashing? Is your output wrong?

On another note, using net lingo (plz, ur, wat da, wid, and prog) and other other words that people may find to be offensive (hell) will not make people want to help you.
User is offlineProfile CardPM
+Quote Post

juju88
RE: Student Exmple
19 May, 2008 - 10:48 AM
Post #5

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 5

guys plz help me i need to have it done in 10 hours
User is offlineProfile CardPM
+Quote Post

juju88
RE: Student Exmple
19 May, 2008 - 10:55 AM
Post #6

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 5

the problem is there is zero errors / warrnings
User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Student Exmple
19 May, 2008 - 10:58 AM
Post #7

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
Well, if there are zero errors or warnings, then there is no problem!

Seriously, what happens when you run the program.

Does it just crash?
Is the output wrong?
User is offlineProfile CardPM
+Quote Post

juju88
RE: Student Exmple
19 May, 2008 - 12:57 PM
Post #8

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 5

it works but not like the way
it is supposed to work
maybe theres somthing wrong with data.dat "file"
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Student Exmple
19 May, 2008 - 01:00 PM
Post #9

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 14,921



Thanked: 47 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
[Removed]

~Edit: I'm going to be a good webmaster and moderate myself.


juju88, If you're not going to provide information like "what should the program do", "what is it actually doing" nobody is going to help you. You have to give them more information.

This post has been edited by skyhawk133: 19 May, 2008 - 01:38 PM
User is online!Profile CardPM
+Quote Post

gabehabe
RE: Student Exmple
19 May, 2008 - 01:13 PM
Post #10

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
laugh.gif
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Student Exmple
19 May, 2008 - 06:49 PM
Post #11

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
@juju:
Wouldn't it just have been much easier to say The program freezes at runtime than to go through all of this?

Anyway, what I do is add system ("pause"); after each line in the problem area. This way, when the program freezes, you can pinpoint the problem to be a certain line. From this, I found that your problem lies in your n.AddStudent(); line.

And from this, I've pinpointed the error to be somewhere here:
cpp
        for(int j=0;j<a;j++)
{
input>>z[j];
input>>c[j];

}

What does your input file look like? I need to see what it's reading, so I can check what the variables are supposed to be.

Another note to add to that: void main () == a big no no. It should always look like this: int main () int int int int int smile.gif

This post has been edited by gabehabe: 19 May, 2008 - 06:54 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:08AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month