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
#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;
elsebreak;
}// 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
}
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
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
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.