First time with classes

Pages: 12
I don't think I fully understand as this wasn't taught in my class yet, and I'm having difficulty understanding what you're saying, so I'm going to try to attempt to do whatever you're doing, haha.

What I'm getting out of this is those were examples, and all I have to add is this

1
2
3
4
5
6
7
8
#include <iostream>
#include car.cpp

int main()
{


}


Getting this error

http://prntscr.com/bzp30u
Last edited on
closed account (E0p9LyTq)
I don't think I fully understand as this wasn't taught in my class yet


Then you have something to look forward to, either during class on studying on your own.

I learned C++, and still learning, without the benefit of classroom instruction or lessons, so it isn't that hard. I'm still plugging away at improving my understanding, reading and mashing code together.
Thanks for the encouragement. : )

C++ is fun, but I wish our due dates were longer. Oh well.

I edited what I said above regarding my code.

It said it couldn't find the car.cpp file even though my class is car.cpp.

closed account (E0p9LyTq)
8.9 - Class code and header files - LearnCPP
http://www.learncpp.com/cpp-tutorial/89-class-code-and-header-files/
That was pretty easy to understand.

Alright, well, I did basically what it told me to do I believe.

http://prntscr.com/bzpc28

I made a header file

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
#ifndef CAR_HEADER_H_INCLUDED
#define CAR_HEADER_H_INCLUDED

class Car
{
private:
    //private fields to hold data
    int yearModel ;
    string make;
    int speed;

    //constructor
public:
    Car(int ym, string mk);

void setYearModel(int ym);
void setMake (string mk);
int returnYearModel();
string returnMake();
int returnSpeed();
void accelerate();
void brake();
};


#endif // CAR_HEADER_H_INCLUDED 


It hasn't given me any issues.

However, the cpp for the member functions is saying it can't find the header.

http://prntscr.com/bzpcdz

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
#include <string>
#include "Car.h"

Car::Car(int ym, string mk)
{
    yearModel=ym;
    make=mk;
    speed=0;
}

void Car::setYearModel(int ym)
{
    yearModel=ym;
}

void Car::setMake (string mk)
{
    make=mk;
}

int Car::returnYearModel()
{
    return yearModel;
}

string Car::returnMake()
{
    return make;
}

int Car::returnSpeed()
{
   return speed;
}

void Car::accelerate()
{
    speed += 5;
}

void Car::brake()
{
    speed -= 5;
}
};


I haven't tried to put the header in my main program yet. Trying to figure out why it won't be recognized by the member function cpp currently.
Last edited on
closed account (48T7M4Gy)
Is that a Java textbook, or an object-oriented programming textbook that assumes Java use?

It turns out the book is not a Java book, not a C++ book and not even an 'Any' book. The author explains in the third edition preface that it is "language independent", which is marginally OK given the title of the book. It would be a nightmare for beginners to use unless they are across all the languages used.

As a text for learning any language, let alone C++, it is equivalent to having both arms and both legs tied behind your back. :(
Last edited on
@FBHSIE

Just out of interest, could you supply a link to your actual assignment?

Cheers :+)
Kermot, I don't know how I feel about that, haha. Is that a bad thing?

The woman that admitted me told us it was a C++ book.

This is an introduction to computer programming course, but we were told it would strictly be in C++. Does that mean we were fooled or? This probably wasn't my professors fault. Many people told me things prior before I went into the class because I specifically wanted C++ which is how I ended up here.

TheIdeasMan, yes!

Though, be prepared for quite the screenshots haha.

This is the Card Design he wants us to use.
http://prntscr.com/bzpo93

This is the actual assignment.
http://prntscr.com/bzpoy9
http://prntscr.com/bzpp0y

And where it said use program 14_3 as reference, this is what we are using.
http://prntscr.com/bzppgt
http://prntscr.com/bzppir
http://prntscr.com/bzppl5
http://prntscr.com/bzppo5

We were told to use the beginning as a starting point, so I'm pretty sure the entire program 14_3 isn't supposed to be used as a reference.

What we're supposed to do--by his examples--is this.
http://prntscr.com/bzpqbi

What I'm getting from this and what I just learnt is get a header file and a cpp file.

For the most part that makes sense, but what's confusing me is why he doesn't have two cpp files.

Shouldn't there be one for the member functions and then one for the whole program or is the cpp file with the member functions all included in the program, thus one being the header file--or the class declaration--and the rest being its member functions and the operations in the program using it as #include Car.h?

Not sure what the layout if for or if it's necessary. I don't think it is.

The main focus is putting a class in a separate file and then using it in the main program--which will be in a separate file--so I'm currently trying to get the class in the main file while having the class and main program separate.

Output is supposed to look like this.

http://prntscr.com/bzprkq


Last edited on
closed account (48T7M4Gy)
This is an introduction to computer programming course, but we were told it would strictly be in C++.

Here it is from "the horses mouth", the publisher.
https://www.pearsonhighered.com/program/Gaddis-Starting-Out-with-Programming-Logic-and-Design-4th-Edition/PGM250265.html

The 3rd edition preface on page xiii says the same. And the same for other editions.

I'm not into blaming anybody, least of all the people trying to learn C++ and especially those among them who have no experience with any programming language at all.

If you were advised you would learn C++ from the book, you were advised incorrectly and if it is your sole text for attempting to learn C++ I can understand the difficulty anybody, including you (or I), would have with that. :(

Well that's disappointing, but I'll still try to do my best. : )
closed account (48T7M4Gy)
I'll still try to do my best

That's the spirit, and given the circumstances, the sound advice FG gave you earlier about the LearnCPP site won't go astray and maybe you are nearby a library or you could hire/buy an introductory C++ book.
@FBHSIE

I was hoping for a simple link to the assignment, from your teaching institution - not screen shots from a book. Note that it would be rather unusual for there not to be a link to the assignment on the school's website.
Will do! Do you have any ideas on how to fix my header error for this one?
You have to be signed in to view it which is why I took the screenshots for you.

Our website is D2l.com.
Oh, and by the way, to anyone else viewing, I managed to figure it out.

My professor ended up doing it in a bit of a different way shown here, but I got it.
Hi,

There seem to be a few things not adding up about what you have said so far.

The course is supposed to be "Object Oriented Programming", but your text book only has 1 chapter on that subject.

Our website is D2l.com.


That is a website aimed at schools and teachers, there doesn't appear to be anywhere for a student to login. It did say something about going to the school for instructions for logging in. I would like to see a link on your school's website which describes the course you are doing.

Oh, and by the way, to anyone else viewing, I managed to figure it out.


So you started a new Topic about the same subject, as you have done several times before.

My professor ended up doing it in a bit of a different way shown here, but I got it.


I am trying to imagine, but you a had a very basic error.
No, the course is Introduction to Programming.

Object orientated programming is just a section we're doing.

https://www.frontrange.edu/docs/default-source/programs-courses/catalog-addendum/2015-2016-frcc-catalog.pdf?sfvrsn=10

It's Introduction to Programming. The school I go to is Front Range.

Use ctrl+f and search introduction to pro.

There is a place for students to log in.

See.

http://prntscr.com/bzzxy0

I also didn't start a new topic on this subject.

The car design had little to do with classes. It was more about the actual program.

I simply had to show the person that was helping me the header because they weren't sure what was going on.

With that said, I also doubt I've made the same thread on different topics several times. If anything, I'm poor at naming threads, but I generally don't make the same thread again.

I have three times that I know of, accidentally, however.

I actually managed to finish this program successfully. I'm now doing an Essay one. : )

Last edited on
Topic archived. No new replies allowed.
Pages: 12