C++ error duno how to solve:(

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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include<iostream>
#include<string>
using namespace std;

class advisor
{
      private:
              int id;
              char name[41];
              char rank;
              char password[9];
              int nbrAdvisees;
      public:
             advisor()
             {
             id=0;
             strcpy(name,"");
             rank='A';
             strcpy(password,"");
             nbrAdvisees=15;
             };
             
             void setId()
             {
             do{
             cin>>id;}while(id>9000||id<1000);
             };
             
             void setName()
             {
             cin.getline(name,40);
             };
             
             void setPass(char Rank)
             {
             rank=Rank;
             };
             
             void setPassword()
             { 
             int x=strlen(password);
             if(x<8||x>8)
             do{
             cout<<"The password should be equal to 8 characters.Re-enter it:\n";
             cin.getline(password,8);
             x=strlen(password);
             }while(x<8||x>8);
             int p1=0,p2=0;
             do{
            
             for(int i=0;i<8;i++)
             {
             if(password[i]>='A'&&password[i]<='Z'||password[i]>='a'&&password[i]<='z')
             p1=1;
             if(password[i]>='0'&&password[i]<='9')
             p2=2;
             }}while(p1!=1||p2!=2);
             };
             
             void setNbrAdvisees(int nbr)
             {
             nbrAdvisees=nbr;
             };
             
             
             float getId()
             {
             return id;
             };
             
             string getName()
             {
             return name;
             };
             
             char getRank()
             {
             return rank;
             if(rank=='A'||rank=='a')
             cout<<"Advisor";
             if(rank=='C'||rank=='c')
             cout<<"Chairperson";
             if(rank=='D'||rank=='d')
             cout<<"Dean";
             };
             
             string getPass()
             {
             return password;
             }
             
             int getNbrAdvisees()
             {
             return nbrAdvisees;
             }
             
             int incrementNbrAdv(int incrnbr)
             {
             if(nbrAdvisees<50)
             nbrAdvisees+=incrnbr;
             if(nbrAdvisees>50)
             {
             nbrAdvisees-=incrnbr;
             // if NBR=nbr+cout
             }
             };
             
             void print()
             {
             cout<<"The id you entered is: "<<getId()<<endl
             <<"The name you entered is: "<<getName()<<endl
             <<"Rank: "<<getRank()<<endl
             <<"Password: "<<getPass()<<endl
             <<"Number of advisees: "<<getNbrAdvisees()<<endl;
             
             int m=strlen(name);
             char namecopyed[40-m];
             for(int n=0;n<m;n++)
             &name[n];
             int u=0;
             &name[u]=&name[n];//this is the error i dunno why:(
             for(u=0;u<40-m;u++)
             {*name[u]=*namecopyed[u];
             if(n<m)
             n++;}
             
             char t=name[];
             cout<<"E-mail: "<<t<<namecopyed<<"@ndu.edu.lb\n";
             };
             
};             
             
A print function to print all the attributes of an advisor: id, name, rank, password and nbrAdvisees. This function should also generate and print the email of the advisor. You should generate the email as follows: the first letter of the first name, followed by the last name, followed by “@ndu.edu.lb”. For example, the email of James Bond would be JBond@ndu.edu.lb
Last edited on

Please edit the post so that it uses code tags - the <> button on the right.

You might get more responses if you do this

Cheers
Last edited on
You should also post the error you're getting
121 In member function `void advisor::print()':
121 name lookup of `n' changed for new ISO `for' scoping
using obsolete binding at `n' using obsolete binding at `n'
118 using obsolete binding at `n'
127 expected primary-expression before ']' token
118 C:\Users\Ray\Desktop\university\CSC 213\assignment 1(part2).cpp using obsolete binding at `n'
Here are the errors I see:
Line 66: getId is declared as returning float, but returns int.
Line 117: The size of namecopyed is not a constant.
Line 119: This statement is a no-op.
Line 121: This statement makes no sense. Why are you taking the address of name on each side? Isn't this what you want?
 
name[u]=name[n];

Line 123: Again, this statement makes no sense. You're trying to use a character as a pointer.
Line 124: n is undefined. n went out of scope at the end of of it's for loop (line 119).
Topic archived. No new replies allowed.