problem in the class

hi
first i want to thank you guys for helping me alot in c++
until this day in this forum.
and 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream.h>
#include<stdlib.h>
using string stdlib;

struct coursesdetails{
      string coursename;
      int coursenum;
      string coursedesc;
      coursehoursnumber;
      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
Hi, u should probably separate the implementation with the declarations in ur class if it's going to be longer than 1 or 2 lines...

What type are lines 9 and 10 ?

line 23: I think u'r looking for add[i].coursename //note the position of the [i]
coursename is not an array of strings, it is 1 string
but add[100] is an array of coursedetails structures

Last edited on
thank you brother
line 9 and 10 they should be int
but you know i didn,t revise the code but i will after knowing the write code,
there are some details ,i wrote comment next to it but the small details i will try to fix it after that
thank you for your replay and i realy dont know how to rate your comment or give like or something like that in this forum .
thanks again
Last edited on
You're welcome :D

This forum doesn't have a 'like' system. If u feel that your original problem is figured out then there's a 'Mark as Solved' at the top somewhere.

Cheers ~


PS: lines 90, 92, 93 remove the " " marks since u want to store an integer and not the value of the character represented by the char in the " "
Last edited on
1
2
3
4
5
6
       
                 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; 


Never change the arrows mid line. Cin is always >> and cout is always <<.
I see you still haven't learned about local scoped variables.
You're still making the same mistakes you made in your patient index exercise.

For example, in the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
     }
}

If you enter 1 for pick and some value for num, what do you think you are printing?
The print array has never been initialized. You're going to be printing garbage.
Topic archived. No new replies allowed.