Issue in C++ course

I have an issue with one of the lectures in the C++ course.
Here is the link:

C++ Functions Standford Lecture is unavailable.

Did not work for me either, I guess the content has been removed from Youtube.

1 Like

Thank you for the feedback

Hey I dont see where i am wrong, making my constructor inside of my class, but when I run the code, I am getting this messages.

#include <iostream> #inlcude<strings>
using namespace std;

class Person{
    
    public:
        string name;
        int age;
        string gender;
        
    Person(string n, age a, string g){
            name = n;
            age; a;
            gender = g;
        }
        
        void printInfo(){
            cout << "The name of the person is " <<name<<endl;
            cout << "The age of the person is " <<age<<endl;
            cout << "The gender of the person is " <<gender<<endl;
        }
};

int main(){
    
    //Person jacob = {"Jacob", 37, "Male "};
    Person jacob = Person("Jacob", 37, "Male");
    jacob.printInfo();
    return 0;
}

1 Like

am just a student here and I have not even started programming yet so please forgive me if am wrong but looking at the code you have missed spelt include for you string #inlcude on your top line, maybe this is the problem as the errors are referring to your strings.

2 Likes

@Jacob_M Also I think its #include <string> and not #inlcude <strings> so correct the spelling mistake and remove the s from the strings. again am still on Ethereum 101 and not starting any coding yet so could be wrong. another note, maybe it should be string a not age a.

1 Like

Thank you, actually i think the include should be there, I think i just tried to add it, to see if this was the issue, but for sure the wrong spielling would not help it hehe… Enjoy the course my friend.

1 Like

no problem, also not sure if this is correct but looks like you are trying to use a string on a number, shouldn’t it be an interger? maybe something like this.

Person(string n, string g, int a) { name = n; age = a; gender = g; }

1 Like

Hi Jacob

I see 2 issues in your code.

The first issue is that

Should be

Person(string n, int a, string g)

You want the constructor to specify a variable of type integer (int) that you call a as an argument to your constructor.

The second issue that

age; a;

should be

age = a;

Because you are assigning the argument “a” to the internal variable “age”.

Hope this helps!

4 Likes

This would also work, you have switched the order of the arguments in the constructor function but that doesn’t affect the code as long as you use the same order when you are initiating the object later on.

2 Likes

@Ivan The general lecture from MIT at the beginning of the C++ course is talking about Python, not C++. Can this be changed?

1 Like

Hello sir, did you refer to this one?
Optional: Introduction to Computer Science - MIT Lecture

I’m checking it myself, is not exactly about C++, is more about computer science in general. Still if that’s not the lecture, let me know so we can fix it ASAP.

If you have any doubt, please let us know so we can help you! :slight_smile:

Carlos Z.

Thank you Carlos, yes that is the one I was referring to. I am sure there are similar ones that would be more specific to C++.

1 Like

Indeed sir, but its an optional lecture, just to give you a better understanding on how computers works under the hood before you jump directly into the action of Programming Language (which is more complex if you do not know the basics of computer science). So it’s not a mandatory lecture, just optional.

Still, there are plenty of videos on youtube about c++ that can give you a more deep understanding of it.

If you have any doubt, please let us know so we can help you! :slight_smile:

Carlos Z.

Hi Carlos,
Hope all is well, Im having another issue with my C++. I’ve programmed the function but im receiving an error message. The syntax looks correct but not running , can you please take a look? Thank you.

1 Like

Did you use () for the function body? You should use curly braces {} :slight_smile:

1 Like

Yes that was the problem, thank you.

1 Like

hi Alko, hope all is well, Im in local/global scope course , Im having an issue with a global variable , can you take a look for me? Thank you for your time.

1 Like

I think you forgot to declare the variable type, which could be int. So just add int at the beginning of the globalNumber declaration.

Carlos Z.

1 Like

Hello, I am having a heck of a time being able to save my completed C++ files and then be able to open them again at a later date, see error in snip below.

How should these be saved? I know I moved them into another folder because it didn’t seem to want to work with more than 1 file in the folder at a time? I’m assuming they need to have a pathway and in moving them i have messed with that but I have moved them back and that didn’t fix them. how do I re-route them and get them to work again?

Please advise.

Thank you.

I figured out the error but still wondering how to save these files? See snip below for how I am saving them.

1 Like