class and table

Hi all i'm newbie in C++ so i got some questions because our teacher is sooo stupid and he never answer in any question T_T
first of all hi to all! 2nd i created some programs and i want you to tell me if they got any problem cause my computer can't run the borland cobiler so i've got huge problem here with my college, and 3rd sorry for my poor english.

I want to create a class named car,
1) The attributes of order car will be the final speed, the acceleration and the consumption
2) create a layout that accept prices for the all attributes of age-group and it cedes him in them. Layout it will give in absentia prices 0 in the all attributes
3) create a method changeMaxSpeed which will change the speed and will have it as the new final speed
4) create a method printCar which will print the three attributes of car
5) create a table from ten cars and you call the layout of age-group in order to take initial prices the cars
στ) Use the changeMaxSpeed in order to you change final speed of car
6) Call ten times printCar in order to are printed the attributes of ten cars

so far i got this:
class car{
private:
int final_speed;
int acceleration;
int consumption;
public:
car(int a=0, int b=0, int g=0){
final_speed=a;
acceleration=b;
consumption=g;
~car(){}
void changemaxspeed(int a){
final_speed=a;
}
void printCar(){
cout<<"final speed is: "<<final_speed<<endl;
cout<<"acceleration is: "<<acceleration<<endl;
cout<<"consumption is: "<<consumption<<endl;
}
};

int main(){
car c;
const N=10;
int cars[N];
for(int i=0;i<N;i++){

if u would answer today i will appreciate it really, and some programs that ive done so far is this:

1) it wants to see if a name is with "man" or "woman" examble batman.
and it wants to return a price of bool and print the 1st "bat" and 2nd "man" or if there's no bat or man in the string it will print just the whole word.
is this works? or i'm really newbie at c++?
(PS: it want only the function not the main)

void seperate(string name){
string name=name;
string str1
string str2
size_t found;
bool k;
k=false;

found=name.find("woman");
if(found!=string::npos){
str1="woman";
str2=name.erase(name.end()-5)
cout<<"string 1st :"<<str1<<" "<<"string 2nd :"<<str2<<endl;
k=true;
};
found=name.find("man");
if(found!=string::npos){
str1="man";
str2=name.erase(name.end()-3);
cout<<"string 1st :"<<str1<<" "<<"string 2nd :"<<str2<<endl;
k=true;
};
cout<<"string 1st :"<<name<<endl;
return k;
};

2) it want's to open a txt file named titles.txt and in this exist 4-5 names that some of them got the Ph.D. in the end and it wants to read and save it in 3 tables with 1000 size and after that to check what name is with "Ph.D." and save that names into a new file named "doctorates.txt" !
this is what ive got so far is this working?

void getline(fstream &f, string &s){
char c[1000]={0};
f.getline(c,999);
s.assign(c);
}
int main(){
ifstream g;
const int N=1000;
int i=0;
size_t found;
string a1[N]={""};
string a2[N]={""};
string a3[N]={""};
g.open("titles.txt" ,ios::in);
while((!g.eof()) && (i<N)){
getline(g,a1[i]);
getline(g,a2[i]);
getline(g,a3[i]);
i++
}
g.close();
ofstream f;
f.open("doctorates.txt");
for(int j=i-1;j>0;j--){
found=a[j].find("Ph.D.");
if(found!=string::npos){
f<<a[j]<<endl; }
}
f.close();
}


thanks, Sincerelly
Iwannhs Rodoviths from Greece.
Last edited on
This will help you with classes: http://www.cplusplus.com/doc/tutorial/classes/

- Right now your function "printCar()" is not a member function of your "car" class, so it will not be able to access the private data.

- That whole section dealing with your past projects is uneccessary. You should delete it.
Sorry friend, I contribute to this site during down time at work and since I AM the Sys Admin it would be a little hypocritical for me to be jumping onto Facebook.
Topic archived. No new replies allowed.