CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2012
    Posts
    8

    hii need help please

    hi
    how are you guys
    i hope you all fine
    here ,, i have homework to do , program that can add and edit and print
    and put a deffault values for the courses and i should do it in class
    and i should do the same these things in another class called student
    but iam now in first step so if i can fix the problem here i will fix it also in that class
    here
    the courses class (please guys read the comments because all my questions and notes there)
    yeah and also please guys iam not in much in c++ because of that iam moving in easy without parameters and byval and byref
    here
    Code:
    #include<iostream.h>
    #include<stdlib.h>
    using string stdlib;
    
    struct coursesdetails{
          string coursename;
          int coursenum;
          string coursedesc;
         int  coursehoursnumber;
         int  coursehoursapproved;
          };
          
          class courses{
                private:
                int add,edit,print;
                public:
                       void addnewcourse()//idont want to put anything here in parameters
                       {
                            coursesdetails add[100];
                            const studentnum =100;
                            int ex;
                            for(int i=0;i<=studentnum; i++)
                            cin>>add.coursename[i];
                            cin>>add.coursenum[i];
                            cin>>add.coursedesc[i];
                            cin>>add.coursehoursnumber[i];
                            cin>>add.coursehoursapproved[i];
                            cout<<"if you want to continue press 1 or 2 for exit"<<endl;
                            cin>>ex;
                            if (ex == 1)
                            continue;
                            else
                            break;
                            
                            }// but the problem is the value of "i" will return to 0 when he pressed 2 and maybe there are more smitakes
                            ;
                            
                void print(){//also here i want it to be empty 
                coursesdetails print[100];
                int pick,num;
                string name;
                
                     cout<<"press 1 if you know the record num or press anynumber if you know his name "<<endl;
                     cin>>pick;
                          if(pick == 1){
                     cout<<"enter the num"<<endl; 
                     cin>>num;    
                    cout<<print.coursename[num]<<endl;
                     cout<<print.coursenum[num]<<endl;
                     cout<<print.coursedesc[num]<<endl;
                     cout<<print.coursehoursnumber[num]<<endl;
                     cout<<print.coursehoursapproved[num]<<endl;
                     
                     else
                     {
                         cout<<"enter his name"<<endl;
                         cin<<name;
                         //here i realy dont know how to do it , i have but it is wrong
                     }
                     }
                    
                    
                     void editcourse(){ //also here ,and i realy still dont know the deffrent between add and edit but here what i did
                    coursesdetails edit[100];
                     string name;
                     int num,pick;
                     cout<<"pick the record number that you want to eidt or its name"<<endl;
                     cin>>pick;
                          if(pick == 1){
                     cout<<"enter the num that you want to edit"<<endl; 
                     cin>>num;   
                      cin>>edit.coursename[num]<<endl;
                     cin>>edit.coursenum[num]<<endl;
                     cin>>edit.coursedesc[num]<<endl;
                     cin>>edit.coursehoursnumber[num]<<endl;
                     cin>>edit.coursehoursapproved[num]<<endl; 
                     }
                      else
                     {
                         cout<<"enter his name"<<endl;
                         cin<<name;
                         //same problem here :)
                         }
                         }
                         
                         void deffaultvalues(){ //in this place if the person doesn,t add anything the record should have deffault information
                         // and here i realy dont know what should i do except 1 step and iam sure it is wrong
                         coursesdetails deffault[100];
                         deffault.coursename = "computer";
                         deffault.coursenum = "10";
                         deffault.coursedesc = ".....";
                         deffault.coursehoursnumber = "4";
                         deffault.coursehoursapproved = "3";
                         // it is wrong iam sure about that iam just trying to explain what i want 
                         }
    thank you again

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: hii need help please

    break and continue won't have much effect in your code. They work only when inside of loops.
    You are missing some curly braces.
    Code:
    void addnewcourse()//idont want to put anything here in parameters {
         coursesdetails add[100];
         const studentnum =100;
         int ex;
         for(int i=0;i<=studentnum; i++) { // << missing
             cin>>add.coursename[i];
             cin>>add.coursenum[i];
             cin>>add.coursedesc[i];
             cin>>add.coursehoursnumber[i];
             cin>>add.coursehoursapproved[i];
             cout<<"if you want to continue press 1 or 2 for exit"<<endl;
             cin>>ex;
             if (ex == 1)
                  continue;
              else
                   break;
                            
         } << missing
    }
    proper indentation helps finding this kind of mistakes.

    I didn't check the logic of your program

    Kurt

  3. #3
    Join Date
    Jul 2012
    Posts
    8

    Re: hii need help please

    thank you brother
    but i dont care about these errors
    i asked some questions in the comments and i hope if you can help
    thank you

  4. #4
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: hii need help please

    Quote Originally Posted by thunderxlight View Post
    but i dont care about these errors
    I'm sorry that I didn't understand any of your other "questions"
    Kurt

  5. #5
    Join Date
    Jul 2012
    Posts
    8

    Re: hii need help please

    ohh sorry brother
    first i realy have exam tomorrow about this homework so if i dont find answer i will lose 30 marks ( i swear)
    10 marks for the homework and 20 for the exam which talk about these thing and i just know this homework today

    and you know f you take close look at this program it doesn,t its job because i want program do these things
    1- addnewcourse : course name , course num ...etc
    2- editcourse: so when you add course name and all the proptises of te course num hourse ..etc you edit it
    and change some of th course proptiese
    3- i want to course but you should give the course name or num itcan do search for it then print it
    4- iwant to do deffault method that will add deffault proptiese to the course if you dont put it in add

    that is all andif you check again and my comments you can understand what i want better but please i realy mr.zuk need help because if i dont pass in the exam tomorrow i will study the year again
    thank you alot zuk and i hope if you can help me because i realy all my best and it still kinda hard.

  6. #6
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: hii need help please

    If that program is due tomorrow then you're quite late.
    Your main mistake is that the couresdata that you're manipulating or printing is local to the functions.
    That is why the data is lost after input or prints uninitialize rubbish in the print function.
    Kurt

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: hii need help please

    Quote Originally Posted by thunderxlight View Post
    ohh sorry brother
    first i realy have exam tomorrow about this homework so if i dont find answer i will lose 30 marks ( i swear)
    10 marks for the homework and 20 for the exam which talk about these thing and i just know this homework today
    All of that is your problem, not ours. Your post is no more important than any other post on CodeGuru. Just because you say it's "urgent" doesn't make your post a higher priority.

    Second, even the first lines are wrong:
    Code:
    #include <iostream.h>
    #include<stdlib.h>
    using string stdlib;
    The correct header is <iostream>, not <iostream.h>. Second, where is the #include <string> for the string class? And what is this supposed to do?
    Code:
    using string stdlib;
    and you know f you take close look at this program it doesn,t its job because i want program do these things
    It can't do its job because the code is not valid, as pointed out above:
    Code:
    #include <iostream>
    #include <string>
    //...
    using namespace std;
    Even if you made those changes, your program is still faulty:
    Code:
    void addnewcourse()//idont want to put anything here in parameters {
         coursesdetails add[100];
         const studentnum =100;
         int ex;
         for(int i=0; i<=studentnum; i++) { 
              cin>>add.coursename[i];
    So when i is 100, you are now accessing an invalid item in the array. An array is indexed starting from 0. Therefore the highest element is 99, not 100. So right there, your program may crash due to an illegal access.

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Jul 2012
    Posts
    8

    Re: hii need help please

    ohh , ok
    youknow i realy know that nobody will care about it because you dont fell like me
    thank you for your replay but it is realy dont help at all
    here another thing because iam sure people not gonna care about this
    i will give 250$ to the one who can answer the full question and it doesn,t take from you guy more than 15 minutes
    and here is my email [email protected]

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: hii need help please

    Quote Originally Posted by thunderxlight View Post
    thank you brother
    but i dont care about these errors
    i asked some questions in the comments and i hope if you can help
    thank you
    You really should, because they're very significant logic errors in your program and an fundamental misunderstanding of how some of these statements work on your part.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured