Problems with first ever C++ Program

I just started C++ and I'm getting a bunch of errors and I don't know what they mean. I did some searching and found some similar stuff but nothing this simple.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
class Car(
public:
    void setMake(string a) (make = a;)
    void sedModel(string o) (model = o;)
    void setYear(unsigned y) (year = y;)
    void setPrice(unsigned p) (price = p;)
    string getMake() const; (return make;)
    string getModel() const; (return model;)
    unsigned getYear() const; (return year;)
    unsigned getPrice() const; (return price;)
private:
    string make;
    string model;
    unsigned year;
    unsigned price;
    );


Here are the errors. Once I understand one or two of them I can probably fix the rest.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
31.cpp:4: error: expected unqualified-id before "public"
31.cpp:4: error: expected `)' before "public"
31.cpp:5: error: expected unqualified-id before ')' token
31.cpp:6: error: expected unqualified-id before ')' token
31.cpp:7: error: expected unqualified-id before ')' token
31.cpp:8: error: expected unqualified-id before ')' token
31.cpp:9: error: expected unqualified-id before "return"
31.cpp:9: error: expected `)' before "return"
31.cpp:9: error: expected unqualified-id before ')' token
31.cpp:10: error: expected unqualified-id before "return"
31.cpp:10: error: expected `)' before "return"
31.cpp:10: error: expected unqualified-id before ')' token
31.cpp:11: error: expected unqualified-id before "return"
31.cpp:11: error: expected `)' before "return"
31.cpp:11: error: expected unqualified-id before ')' token
31.cpp:12: error: expected unqualified-id before "return"
31.cpp:12: error: expected `)' before "return"
31.cpp:12: error: expected unqualified-id before ')' token
31.cpp:18: error: expected unqualified-id before ')' token 
You're using wrong syntax

1
2
3
class car { // notice the '{' not the '('
public:
      void setMake(string a) { make = a; } // same as above, note you need to include <string> 


There you're only problems... I think (its 00:25!!!!)
So I fixed the original syntax errors but I'm still getting some

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
class Car{
public:
    void setMake(string a) {make = a;}
    void sedModel(string o) {model = o;}
    void setYear(unsigned y) {year = y;}
    void setPrice(unsigned p) {price = p;}
    string getMake() const; {return make;}        //This line still has an error
    string getModel() const; {return model;}      //This line still has an error
    unsigned getYear() const; {return year;}     //This line still has an error
    unsigned getPrice() const; {return price;}    //This line still has an error
private:
    string make;
    string model;
    unsigned year;
    unsigned price;
    };


Here's the errors that remain

1
2
3
4
31.cpp:9: error: expected unqualified-id before '{' token
31.cpp:10: error: expected unqualified-id before '{' token
31.cpp:11: error: expected unqualified-id before '{' token
31.cpp:12: error: expected unqualified-id before '{' token
Remove the ";" on the erroneous lines.

That is, the ; after const.

This code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
class Car{
public:
    void setMake(string a) {make = a;}
    void sedModel(string o) {model = o;}
    void setYear(unsigned y) {year = y;}
    void setPrice(unsigned p) {price = p;}
    string getMake() const {return make;}
    string getModel() const {return model;}
    unsigned getYear() const {return year;}
    unsigned getPrice() const {return price;}
private:
    string make;
    string model;
    unsigned year;
    unsigned price;
    };

int main() {
    std::cout << "Yeah...";
}


Compiles with GCC. I added a main function for obvious reasons.
Last edited on
Thanks
No problem.
Topic archived. No new replies allowed.