Learn C++: Build Fast & Efficient Software | Robert Slattery | Skillshare

Learn C++: Build Fast & Efficient Software

Robert Slattery

Learn C++: Build Fast & Efficient Software

Robert Slattery

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
26 Lessons (1h 53m)
    • 1. Trailer

      0:56
    • 2. What is C++?

      0:28
    • 3. Intro to C++: Declarations, Definitions & Initialization

      2:58
    • 4. Intro to C++: Class, Struct, & Enum

      1:22
    • 5. Intro to C++: Access Modifiers

      0:34
    • 6. Intro to C++: Header vs. Source Files

      1:28
    • 7. Intro to C++: Overview of the Standard Template Library

      0:49
    • 8. Intro to C++: Input and Output

      1:45
    • 9. Intro to C++: Built-in Types

      1:35
    • 10. Intro to C++: Arrays

      0:48
    • 11. Intro to C++: Conditional Statements

      2:00
    • 12. Intro to C++: For/While Loops

      2:08
    • 13. Intro to C++: Overview of Pointers

      2:35
    • 14. Intro to C++: What is "int main()"?

      0:59
    • 15. How to Install Microsoft Visual Studio For Windows

      5:03
    • 16. Planning How to Build a Hotel Reservation System

      9:22
    • 17. User-defined Types: Hotel

      6:18
    • 18. User-defined Types: Address & Room

      4:33
    • 19. User-defined Types: Admin, Date, Globals, & Creating Child Classes

      5:50
    • 20. User-defined Types: Guest, Finalizing Child Classes

      3:08
    • 21. Variables

      11:29
    • 22. Functions: Creating Booking Functions

      11:08
    • 23. Functions: Creating Date Functions, Operator Overloading

      5:56
    • 24. Finalizing Constructors

      10:40
    • 25. Functions: Finalizing Booking Functions

      9:36
    • 26. Conclusion: Let's Book a Guest!

      9:44
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

305

Students

--

Projects

About This Class

Are you interested in learning how to code 3D graphics, animation, or video games?  Maybe you want to create systems for airplanes, automobiles, desktops; or, perhaps you want to build robots and AI?  Then, welcome!  In this class, I’m going to teach you the foundational concepts of C++: a fast and efficient programming language that is used in every PC worldwide.  This is great for creatives and designers who want to expand their knowledge and build the systems of the future.  Anyone can take this class and follow along with my step-by-step instruction.  At the end of this class, you’ll have enough knowledge to start building your own C++ apps.  I am excited to see all the cool stuff you guys end up building on your own.

Meet Your Teacher

Hello, I'm Robert.  I am an Information Security Analyst and Microsoft Certified IT Professional (MCSE, MCSA). On Skillshare, I make programming videos for beginners and advanced users.

Connect with me on LinkedIn with a message introducing yourself: https://www.linkedin.com/in/robert-slattery

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Trailer: have you wanted to learn secrets West by jumping right in the building out? There is a huge demand for c++ programmers in the tech industry. This class is aimed for beginners and experience programmers alike and is a student applying the C plus plus language to real world problems. No experience is necessary. We'll talk the basic terminology of C plus plus and apply what we've learned to book a guest into a hotel, using a simple reservation system that we'll build together to learn about variables. Functions object Orania Programming Inheritance is, well, Asato planning projects. This will help you become a better software engineer if you want to build video games. Desktop applications systems for automobiles, airplanes, Defense Robotics is well as three D graphics and animation in this class is for you. At the end of this class, you'll have a foundational knowledge of how to plan set up in build c++ projects and scratch. You'll be able to create show naps in no time 2. What is C++?: So what does C Plus plus C Plus bus is a general purpose programming language that allows imperative, object oriented and generic programming features while allowing for low level memory manipulation. Example. Usages include systems programming, embedded programming, desktop applications, servers and video games. It is designed for performance, flexibility and efficiency. 3. Intro to C++: Declarations, Definitions & Initialization: Hey, guys, in this video, we're going to learn about the basic terminology of C plus Plus is well as variables and functions. Before we can have a discussion on how to use the language, we're going to talk about terminology so that we don't get confused. These air declarations declarations tell the compiler about the name of a type of something , so we have externally into number Bull toggle button bull enable in failed Boyd Run class hotel. So we look at X turn in number with a semi colon. That is an object declaration. And what's the semicolon? Well in C plus, plus we and lines with a semi colon. Don't forget to add those. Each Functions declaration shows its signature, which are the parameter in return types. So in this case of toggle button, it's bull enable. So if those air declarations than these are definitions, the definition will provide the compiler with details that the declaration doesn't have. So for an object definition is where the compiler allocates memory for the object and for a function. The definition provides the code instructions. So we go ahead and look at the left picture class hotel. You're looking at a class definition and it is opened up with brackets. Pay close attention that closing a bracket class or even instruct must end with a semicolon . So you have there where it says car, get I D. While as we just learned, that is a function declaration now, in order to define a function that's a member of a class who must write, it is so car hotel, colon, colon get I. D. If you forget to write that the compiler will not know that get I. D is a member of the hotel class. Now, if you look over at the top here where it says bull toggle button, this does not have a class in front of it because it is simply just a function definition on its own. So in number equals five is an object definition bull toggle button bull enable is a function definition, which will return the results in the third picture. We have some more function definitions. If you look at the one on the bottom that says void run, you will see that it does not return anything because a void is an incomplete type in C plus plus, and thus does not return a value. As you can see with full and end, these functions will return value, so that should get you more familiar with the difference between a declaration and a definition. Another term to know is initialization. Initialization is the process of giving an object its first value in C plus. Plus, you typically generate objects from Struck's and classes, so initialization is performed by constructors. 4. Intro to C++: Class, Struct, & Enum: Let's talk about classes, trucks and items. Go ahead and pull up your text under and let's do this together we're going to create a class called hotel. Make the Classic definition. The class is a user to find type or data structure that has data and functions as members whose access is controlled by private protected or public access. Modifiers. Memory is allocated when a classes created or in stan she hated, but not when it's defined. By default, all members of a class have private access. Let's now create a definition for instruct. Called address Instruct is a collection of variables of different data types under a single name. It has similar characteristics to a class. Struck members have public access by default, while class members have private access by default. Like a class, memory is allocated when instruct is created or in Stan Shih ated, but not when it's defined. Enumeration or Denham is a user to find type that consists of Integral Constance. Since C Plus plus 11. They could be written as Etem class, followed by a colon and then the data type that they inherit from such as car or INT 5. Intro to C++: Access Modifiers: Let's talk real quick about access modifiers. The public access modifier means that all the class members declared within it will be available to everyone. The class members declared his private can be accessed on Lee by the functions inside the class with protected access. The class members are inaccessible outside the class, but they can be accessed by a subclass of that class. 6. Intro to C++: Header vs. Source Files: it's moving on. Let's start talking about files. How do we handle files and c++? Well, the most basic c++ program will have one source file that see PP with an end main function within it. When you start to build out classes and other data structures, then you're going to be working with a lot of header and source files. You can think of it like this. The header file. We'll have your classes object and function declarations as well as an include guard such as hashtag pregnant. Once you'll see that at the top, the source file then is the implementation. It has your object function definitions and a include to the header file of the class. The whole purpose of this structure is efficiency, and the C plus plus language does this to distinguish declaration and definition. That being said, if performance is 100% necessary to your program than it is faster and more efficient to make declarations and definitions in a header only file through a process called in lining . But for now, just know that when you create a class and C plus plus, it will have a header and a source file and you'll see that I wrote that the header can have a dot h or dot each plus plus. Typically when you're using C plus plus, you'll want to use the H plus plus ending to the file. 7. Intro to C++: Overview of the Standard Template Library: the standard template library is basically devoto algorithms, containers it aerators and much more basically, to make your life as a C plus plus programmer much, much easier. So a few good ones to start with to be the following the vector container, which is an array, a dynamic array that has continuous elements within it. The list, which is based on the doubly linked list data structure. And then I included two others. The map and the UN ordered map, which essentially store a key value pair. I'm not going to go over these here, but if you intend to become a C plus plus programmer, these air four containers that you want Teoh spend a lot of time getting familiar with. 8. Intro to C++: Input and Output: Let's talk about input. Now put take out a text editor and follow along with me in C plus. Plus, you can read a single white space separated token using CNN and print output using C out i o Stream stance wore standard input output stream. This header file contains definitions toe objects like CN See out and see her looking at our example here we have include Io Stream and in in main function. So we'll right out of comment. Declare a variable into X lad. Another comment read in value. Then we can write standard see out at the insertion operator and in parentheses. Enter a number, then standard CNN, followed by the extraction operator X for CNN. The input devices, usually the keyboard. The extraction operator is used for reading inputs. No, we want to find out our value standard. See out X standard in line See out is used to produce output onto the display screen. The insertion operator is used to display outputs. Finally, standard see out insertion operator in parentheses. We'll add a space and type. Your number is colon X. Lastly, we will return zero. So this is a basic example of how input and output works in C plus plus 9. Intro to C++: Built-in Types: Let's take a look at some common built in types and C plus plus. As a beginner, you will want to become familiar with ease. We have the car which is a representation of a character, said Socar. I d equals in quotes to CBE. FD could be whatever sort of character set that you need for your program. We have the bull or Boolean, which is basically a data type that is either set to true or false. Sobule is valid equals true Bullis set up equals false. You have a numerical integer types in the most common that you're going to see in particular with the type of program are gonna be writing is the end. So end count equals three. We declare int and in it with the value. Also worth noting is that the end is a 32 bit integer that is four bytes in size now. Sometimes you will also need numbers with really, really fine precision. And we use what are called floating point types in that case namely, the float in the double, so you can see here the difference between afloat in a double. Lastly, you should also become familiar with strings, particularly string from the C++ Standard Library, which will require using the include directive string Like a car. A string is basically a sequence of characters, so you'll see it often used for names and other types of data. Okay, so those are some basic built in types receive, plus plus, Let's go ahead and move on to a raise. 10. Intro to C++: Arrays: so raise air important to know in software engineering in general in a raise a collection of items that are stored at continuous memory locations in C plus. Plus, you will see them written like this so you can make an array declaration by using a Pointer Ray declaration by initializing elements or a declaration by specifying size and initializing elements or array declaration by specifying size. And then, in order to access particular index, you can simply write it like this small array at index zero equals three. Smaller rate index one equals six and smaller. A index two equals five. Using a raise will significantly reduce redundant lines of code, so use them often. 11. Intro to C++: Conditional Statements: So let's move on to conditional statements. You will need to know if else if, and l statements to know basically where your program is going. This is where a decision making takes place in C plus plus, basically, we're asking the question. Where do we want to statements execute what conditions need to determine that the if statement will execute a block of statements given that a certain condition is true. And if the condition is false, then the statements within else will be executed now else if is another condition when neither the condition within if or else is to be executed. So looking at this here, if count is greater than zero, then do something. Include your functions. Other statements. LCF count is equal to zero. Do something else else. Do another thing entirely. That's basically how if else, if Nell statements work, they're making the decisions on where your programs going. We also have switched statements and switch statements basically dispatch execution two different paths based on value of expression. So if we have the function void, execute with the in count argument, we can then right switch count open brackets Case one so executed count equals one. Your statements, your functions. Once that's all said and done, you finished by writing Break with the semicolon after it, and then you can move on case to so execute. If count equals two, followed by your statements. Break case three. Execute if the count is equal to three so on and so forth. So now at the end of your switch statement, you write default colon break semi colon as that will execute if the count doesn't match any of the cases. 12. Intro to C++: For/While Loops: Okay. The four loop The four loop is an entry control loop before loop is a loop that will execute a specific number of times. So if you look here it our 1st 4 loop, you'll see that I is our loop variable. So you see, this is written as four and then in parentheses int I equals zero, which is our initialization expression, followed by a semi colon. Then I is less than count outsize, followed by a semi colon. That is our test expression, followed by I plus plus which is our update expression the loop variable. I is initialized and then we check if the variable is less than or greater than something. And if this statement is true, the loop is executed and the loop variable is updated. So within this four loop, all we're gonna do is print the element I So we do. A standard see out for account I count again is a standard vector which is basically a dynamic array in C plus plus. So you can look at that and say, Wow, that's so confusing that so much code. Well, since C Plus plus 11 range based four loops exist so we can write four Hajto keyword, which tells the compiler to automatically deduce the type elements colon count, and then we can print the element and that does this exact same thing as the previous four loop. Now, what if we don't necessarily know the number of times you want to execute a loop while we can use a while? Loop a while Loop will run until a condition or variable terminates it. So in this example, you can see our initialization expression int I equals zero while I is less than 10. Then write your statements, your functions, and then update the expression I plus plus so get used to four loops and while loops because you'll be using him a lot. 13. Intro to C++: Overview of Pointers: go ahead and pull up your text over again with me. So a pointer is a representation of a memory address. So we'll go ahead and write a function called Run, then in value, we can simply say equals five. We will then declare a pointer. So int pointer with the asterisk, you'll see that visual studio will adjust the asterisk to the left, but it can be in the left, middle or right position. Now we can assign the address of a variable to a pointer. It's a pointer equals ampersand value. And then, if we want to, we can assign the pointer to a new value so asterisk Pointer equals 10. Syphilis was to use his pointers because sometimes it is useful to be able to obtain the memory address of a variable during runtime in order to access data at a certain position relative to it. Using pointers can lessen the memory footprint of your program, especially when passing pointers as function arguments to modify variables within that function. I also real quick want to go over pointers and references were not going to get real into this right now, but since our program are going to be building will have both. I just want to quickly describe the difference between them in this example. Hotel Asterisk pointer, The asterisk symbol in C plus plus is a pointer and a pointer is a variable that holds a memory address where the value lives and that memory address can be reassigned two other objects Now. The reference, on the other hand, is more like a constant pointer. So when a reference is initialized, that memory address can no longer be changed. And so that's the main difference between a pointer and a reference. So whenever you create a pointer and you used the key word new in this example hotel asterisk, my hotel equals new hotel. Okay, after you're done with the object, you've called functions from it, you've set variables to new values. You have to use the keyboard delete, so delete my hotel. That's the only way to free that pointers memory back to your machine 14. Intro to C++: What is "int main()"?: So lastly, now that we've covered files, basic data types and all that, you might be thinking. So what is in Maine? What I see in Maine? What is in Maine anyway? Well, in Maine is basically a convention in C plus plus, Ah c++ application must return a small number, typically zero in order to exit the application. And so we're basically given in Maine to do that. This is where you'll be launching a program from. And if you've ever worked with object oriented programming languages before, you've seen this convention in C C. Sharp Java. So just know that in Maine is where we're going to be launching a program from, and if you can return with the exit code of zero, then that means that your program was a success. In the next video, I'm going to show you how to install Microsoft Visual Studio and begin setting up our program 15. How to Install Microsoft Visual Studio For Windows: Hey, guys. So now that we know a little bit about C plus plus, how do we go about using it? Well, you're going to need a text editor and a compiler, and you can get both with an integrated development environment called Microsoft Visual Studio. We're going to be using visual studio for Windows, and this video is for anyone using Windows seven or higher. The community version of Visual Studio is free, so it's perfect for beginners again. This is if you're using Windows. If you're using an Apple or Lennox computer, some good I d alternatives would be X code eclipse or Net beings. So let me go ahead and show you how to get visual studio for your PC. So go ahead and open a browser and go to Microsoft dot com. Okay, in the upper right hand corner, you will see all Microsoft click on that, then in the developer and I t column, you will see visual studio that's you want to click on. So the version that you want is visual studio I D. Here on the left, so highlighting download for Windows, you will click on Community 2019 and that will begin the download process to go ahead and do that. Save it once it's finished, go ahead and run the installer. This pops up. Just click. Continue and just give it a few moments to download and install your files. So it's gonna open the installer interface and you'll see workloads, individual components, language backs, installation locations. I'm going to go ahead and change my installation path, but if you want to use the default one, that's okay, too. So let me do that real quick. So once you've done that, make sure that you have your language of preference chosen. Then click on workloads and you will notice. There are many different frameworks and languages that air supported by visual studio for C Plus plus, the minimal set up requires desktop development with C plus plus, so we will click on that. Once you click on that, you will see it on the right hand side. A list of optional downloads. If you're not on Windows 10 then you can ignore the Windows 10 sdk. Do not install that and you do not need the C plus plus C make tools from windows, either. If you're using Windows seven or Windows 8.1, you could get The SDK is directly from the Microsoft website, so make sure to download and install those after you finish the visual studio installation . After that, we'll click install, and we will wait for that to finish. If you're changing the path, make sure to continue with my device. You can choose to take a survey. I will click. Not now. And it is installing. I will see you guys when that is finished. Okay, so visual studio has finished installing and will now launch and the first window you'll see. We'll ask you whether or not you want to sign in with your Microsoft account. I am not going to do that, so I'm just going to click. Not now. Maybe later. Then it's gonna ask you to choose your environment development settings. General is fine. I prefer dark themes for code editing, since it's easier on the eyes, so I'm gonna go ahead and choose dark. After that, I will click Start Visual Studio. So now we'll bring up this menu and what we want to do is go ahead and create a new project we're going to click on, create a new project which will bring up this templates window. And we're simply going to create an empty project which will start from scratch with C plus plus for Windows provides no starting files. OK, so then we're going to click next, and this is where we're going to name the application. So we're going to go ahead and call it reservation system and choose the install holder. Okay, The project name and solution name can be exactly the same. If you want to do that, it's up to you. Once we're finished, we will click, create, and that will open our project. On the right hand side, you're going to see the Solution Explorer, which is what's going to hold our header and source files. And one thing I always like to do when I create a new project up here where it says debug X 86 I change that to x 64. Since we're targeting 64 bit machines that completes this tutorial at the end of this video , you should have visual studio in C plus, plus tools installed and ready to use on your computer. Next, we're going to begin planning out to build our application 16. Planning How to Build a Hotel Reservation System: Hey, guys, how's it going? I don't think that we can discuss the topic of building an application without first covering planning. I believe that planning is the most important part of software development. I mean, would you try to build a hospital without a blueprint? Of course not. So in this video, I'm going to show you how to plan our hotel reservation system and determine the requirements to do so. I think that being able to visualize your program will make it much easier to understand what it is you're trying to dio. Developers often will use two different types of diagrams to do. This one is the use case diagram, and the other is the class diagram. And we can make either of those with unified markup language or UML. So how would I create a UML diagram? Well, some people can draw them by hand. I personally use a service online. I like Draw That I owe It is a free Web based UML document designer, and it exports to many different types of formats, including JPEG, PNG and PdF, which is what I like to use. So let's go ahead and take a look at our use case diagram for a hotel reservation system in dried out i o. And as you can see, it is a pretty simple, easy to use interface Simply using dragon drop for your shapes for text. Even got a little stick figure guy here If you were Teoh, start this project on your own. Indra dot Io, Open up your browser going to draw that I owe. The first thing you'll see is you get to choose what, Dr that you're gonna be saving too. So I'm using my device and then create new diagram. I'm using the basic blank diagram, but there are many templates here that you can choose from. And it really goes to show how this service really applies to any industry, not just software development. So you'll create a new entitled diagram. If you open up the UML tab, you will see this is where you can drag in your last name boxes. Edit them as you will go to file export as pd out. For example, if I go ahead and go back, Teoh our use case diagram. We know that generally speaking, they're going to be a two actors involved when booking a hotel room. The gassed in the desk work okay. And the guest initially will be concerned with finding a hotel. Right? So the guest will search for hotel and that guest. We'll also be concerned with the dates of their stay the destinations of the city, the rooms, number rooms, the number of guests that are going to stay in that hotel, special rates, so on and so forth. And once the decision has been made to stay at a hotel, the guests will go ahead and book a room. And they do that simply by making a reservation. And once they've made the reservation, then they're going to check in at a later date. The hotel dad ask, which will call the admin, ultimately will issue the room. The room card. Make sure to add the booked room into the hotel system, and that's it. So for our first c++ application, all we're going to do is make a reservation for the room. That's it. Very simple, but also practical. If you're having trouble figuring out where to start when thinking about problems like this , the thing that I like to dio is to break things down into smaller problems or components, and I like to use word association. So we're dealing with a hotel. So I think hotel room, bathroom sweet made clerk so on and so on and so on and so on. And by thinking like this, ultimately I have a clearer picture of the use cases for a reservation system. You'll see. There's 1/3 actor here called System, which basically represents the AI that sends out booking notifications. If, for example, you booked this room online so the system can send out reservation notifications cancellation notifications. Okay, looking at the admin again. The admin, of course, will issue the room. Two. The Guest. There's also the case that they made on a register and update an existing account at the hotel right, issuing the room card, registering the new guest. So this diagram handles the general idea of what we're doing. But there's probably a lot of stuff that's missing here, and the development process could be like that. Sometimes you'll often come back, make fixes or improvements to designs that you've built, and it's really all based on the requirements of the project you're working on. At a given point in its development. Once we have considered our use cases, we can then start to think about what types of data that our applications gonna hold. And that's where the class diagram becomes Useful. Class diagram will show classes and data types in the relationships between them. Since we're dealing with the hotel, we generally already know right off the bat what we need. Why? Because we've all stayed in hotels before, right? This is where using your own experiences can be really helpful in building applications. Opening up the class diagram. You'll notice that it is color coded, so classes are in green, Denham's enumeration czar in the based hand color, and then our struck's will be in blue. And this class diagram is really it. This is the whole application that we're going to be building. We know we're going to have a class called hotel, okay, and we know we should have a class cold room and they'll be different types of rooms, right, so they'll be single rooms. Double rooms will be a suite. There's a reservation class that deals with booking rooms at our hotel, and, of course, the hotel can't book a room itself. So we create an admin class, which is presumably an actor desk clerk Who could do so. So we have our enumeration. Zari NMS 1st 1 room type so they'll be single rooms, double rooms, suites, room status. A room is either vacant or it's occupied Heyman status. Is the room paid or unpaid? Pretty simple. So I'm going to explain real quick how you would read the UML diagram here. So at the top, in the colored box you have date the data type in this case will be instruct. Then in the box below it, we have minus a name Month Colon. And so that is month, the object name into the data type. So these are our member variables within date in the box that's below that. That's separated by a divider. We then have our member functions, so date will have a month, a day in the year. And then we can even split that up into different data types for months, years, days. Also, we need to know addresses. We need to know the address of the hotel so we'll have a data type called address, which has a variable street address. City state, zip code, country which are all string types from the standard library of C plus Plus, the guest will book a room with the name date of birth, email, perhaps even a phone number sex, whether or not they're in adults and so will include all that information in the guest class. Hotel class is pretty easy to think about. We know that a hotel have an I d for war, internal usage, a name and address. And, of course, within a hotel you have rooms. So we're going to create an array using the standard library vector container for our rooms . We'll have a room class. What does the room have? Well, a room will have a number. Ah, floor number. A room will have number of guests. Also, reserved dates were going to be using a map so that we know whether or not this room is booked for a certain number of dates already. And the room has a whole series of functions within it that will be necessary. As you work out this class diagram, you will find Mawr and mawr. They'll have to be added, but this will work for what we're trying to accomplish. Remember, we're simply just trying to make a reservation. The key take away from this video is to always make design documents before beginning a new project. Otherwise, you're going to be spending far more time than it is necessary to build your application. Plus, your teammates will want to go to lunch with you, too. Now that we've planned everything accordingly, we're going to begin building our very first c++ application. 17. User-defined Types: Hotel: Hey, guys. So using her class diagram is a guide. Weaken, begin building our hotel reservation system. As we work through this, I will go line by line so that you can get a better understanding of each component in a C plus plus program. If I'm going too fast or you're having trouble following along, that is okay. All of these project files are available for download. Just follow the link in the description of these videos. So we go back to our newly created visual studio project we named our Is Reservation System . First thing that we're going to dio is we're going to start building out our classes just from scratch. So if you go to the upper right hand corner into the solution explorer and right click the name of your project, you will see an option that says, add. This is where you can add new files or folders. So we're going to create a new class. We're going to create a hotel class and, as you can see, it will populate on its own. The name of the header and the source file. Remember, we're going to be using the H P P extension for header files, and then we're also going to select the virtual destructor option. Once you've done that, will hit OK, and it will create our hotel class for us resemble. Let me get a little closer here. There we go. So when it creates a new class, it's going to have a default constructor and D structure Before we start to get into that, let me show you the source file. It has the definitions of the constructor in the destructor, and that's all that you'll see when you create new classes from visual studio. Let's go ahead and go back to the header file. And let's just talk real quick about everything that we're looking at any class. The class is a user defined type or data structure that as data and functions as members whose access is controlled by private protected or public access modifiers. Remember in a previous video, we briefly discussed the difference between the access modifiers memory is allocated when a classes created or in Stan Shih ated, but not when it's to find. So we have our class hotel, we open up brackets and remember, you have to end the class declaration with a semi corn. Okay. Public, of course, is an access modifier. You also notice pregnant once here, That is an include guard that must always be at the top of each of your header files. OK, so hotel is again are constructor and a constructor. Initialize is objects of the class. They are automatically called when an object or instance of class is created. You will always want to initialize the member variables of your classes in the constructor . So that is our constructor. And below that you will see virtual with the approximation symbol hotel That is the D structure. The destructor is called when the object is out of scope. So it's one of these conditions. The function ends, the program ends. A block containing local variables ends or you delete. Operator is called This destructor is marked virtual. Since it is a base class, this prevents undefined behaviour in C plus plus So you're going to see, as we start adding or other classes here just what we mean by virtual. So if you recall from our terminology, these are declarations, if we go to our source file, you'll see their definitions. We can actually delete those there. So let's say we delete the destructor in the source. Well, now visual studio is telling us Hey, there's no definition for this Destructor. What are we gonna dio? Well, we could remove the semi colon and simply plays brackets. And now the hotel destructor is defined. We can do that in the header file. If we so choose to do so. I'm gonna go ahead and do that since we're not putting anything in our destructor anyways, right now. So when we define a constructor, it looks like this hotel Colon Colon Hotel, which is the name of the class constructor inside the brackets. I'll just write objects to initialize so that it's clear now you might be thinking, What if I don't want to use that constructor to initialize what you can use? Other constructors You can use as many constructors as you like actually to initialize or variables. Let's go ahead and include a second constructor. So this is a second constructor that takes arguments for the hotel I d. The hotel name, address, the total amount of rooms. Or it could be any set of data that you want to write hotel and then in parentheses separated by commas are arguments and you'll notice that rain now visual studio can't find them. And the reason for that is because we haven't included there. Include directives. So we have string in vectors, so well, right. Hashtag include vector for standard vector string for the standard libraries string. Okay, so you see address and room are not found because we haven't created them yet. 18. User-defined Types: Address & Room: So this is what we're gonna do. We're going to go ahead and create our address struck. So going to the solution Explorer here under header files. I'm going to right click again like we did toe ad in New Item. And this time all we're going to do is create a header file for our address. We're not interested in a source. It's not necessary. So Header will name it. Address dot H p p and we'll click. Add And when you do that, this is all you're going to get. Your just going to get the include guard hashtag pregnant ones. So we're right Construct address with our brackets. Remember the semi colon at the end of it That's necessary for classes instructs. And that's it. And we'll come back to the address struck later to give it members. But for now, that is OK. We can return to hotel better. So now that we've created the address, weaken go hashtag include and in quotes address start HBP and we'll save that And now you see a visual studio can see the address Good. You'll see below that standard vector which takes the type room vector again, is a dynamic array. We now have to create our room class. So in the solution, Explorer, under the name of the project will right click. And this time we want a class with both a header and a source file. Because the room is gonna have a lot more logic, for example than address will. So we'll add a class we'll call it Room will change our ending of the header. And that should be good. We'll click. OK, so we have a room with a default constructor and destructor. We'll just save them. Constructor These air the objects to initialize destructor these air the objects to delete . Now you could go back to our hotel and to the top with our include directives. We can know hash tag include room. The age was most and now there's no problems. Very good. So this constructor, like I was saying before you can have any set of constructors, you'd like to initialize your your data. So this one has the idea, the name, address, the total amount of rooms that are in the hotel, and you'll you'll actually notice a little naming convention that I'm using for the object names. So int underscore Hotel I D. That is a convention that I like to use. Ah, you'll see as I start including variables. It's a way to distinguish from other data in the class, so I like to do it that way. So in the hotel dot CPP file, I'm gonna go ahead and copy and paste this real quick just for the sake of efficiency. So Hotel Colin Colin Hotel and then the arguments we have, and then that's it. And within that you'll initialize your objects about two constructors and a destructor. You've talked about classes and struck's access modifiers, so I hope me breaking down the definitions of classes and Struck's instructors and D structures helps you out on your learning. 19. User-defined Types: Admin, Date, Globals, & Creating Child Classes: Now we're going to create a new class called Admin and inside based class. Now I'm gonna type hotel. We'll change our extension. This is where virtual comes into play now. So we're going to select virtual destructor when creating the admin class you've done that will click. OK, and that's gonna look a little different than before. So what, you'll be seeing his class admin colon public hotel. Well, let me first include hotel H plus. Plus, There we go. So what we're looking at is that the class admin is derived. That's what the colon stands. Word from the hotel class. So the hotel class now is a base class, and admin is a child or a subclass of hotel admin. This is our constructor. This is our destructor. And again we're using virtual for a destruct er's to prevent undefined behaviour and C plus . Plus, we're not gonna be going over that in this video, but we could talk about that in future videos. Now we're going to create a new header file called Date that each must was like we were writing in our class. Diagram will just continue struck month obstruct day. We have struck's year and instruct date. Save it. That's it. That's what we need for our date. So I'm going to go into room now, and I'm going to change the destructor to virtual because there's going to be sub classes of rooms. So virtual room Now I'm going to right click on the project name, add a new class and type single room, change the extension in our base classes room with public access. Virtual destructor. So that's our single room. And we need to include room that HBP. And so what? We're looking at here with this and then the admin. The hotel are examples of inheritance in C plus. Plus, we'll save the single groom and we're going to add another class called double Room HBP and again the base class or double room, his room and a virtual destructor greed. Okay, so that's a double room. We're just include room again, like we did for single room. You're probably starting to notice a pattern, save everything. We're going to create another header file under Header that will call Global's DOT HBP and this basically will have the types of data that's gonna be shared among several different classes global's that HBP is where we're going to put our freedoms in, um, class and then the name. So we have a bed type, for example, then colon what type it is derived from. So we're going to use unsigned car and then open brackets, and that's it. So basically, you can choose whether or not the minimum is based off of a car or an ent. I'm using cars because they're only one bite in size, so they're small. Ah, you're more than welcome to use an end, but just remember, it's four times the size of a car. So as your program gets larger and larger and larger, that could be an issue with your memory load. We're gonna have a Needham class bed type, will also have an Emam called room type, another one called rooms status and payment Status. We can actually go ahead and start popular in data and our freedoms, and it works like this. So in bed type, single comma, double comma and twin beds, right, his queen beds, king beds, room type. There'll be a single rooms, double rooms, perhaps sweets, room status, vacant occupied payment status paid for unpaid. So that's how you Dems look in C plus plus, and this works perfectly for a program 20. User-defined Types: Guest, Finalizing Child Classes: going to our solution. Explorer. We're going to add yet another class called guest with HBP as the extension. We're not concerned about inheritance years, so we're just going to click. OK, so we have our guest. We'll just save it out. Will have to create another class that is called sweet and this one is inherited from room the virtual destructor. Okay, that's our sweet will include room that HBP at the tub. We have to create another class. This is our reservation class. So that's just going to be reservation that HBP dot see pp click. Ok, so what are we missing? You know what we're missing were missing are in main function. Are we so under source files Will right click and will add new item and we'll choose C plus plus file. We're just going to name it main dot See pp We'll click Add So we're right in Maine. Intar CSI car with two pointers RV open up brackets and right return zero with a semi colon . Okay, so we're also going to have to include Io stream for this to compile So hashtag include Io stream which allows for input and output will be using that two prints of the council. So standards see out standard and line. Okay, that will be necessary. So you might be thinking, Well, you showed us in Maine without arguments before. What's this? Well, R v and R C R how basically command line arguments are parsed in C plus plus, So are you see will be the number of strings pointed to by RV, and you don't have to be too concerned about that the moment. But that's essentially the purpose behind that. So those air all of our classes Struck's and Denham's for our little hotel reservation system here. At the end of this video, you should be able to distinguish the difference between classes, trucks and Denham's. Now that we have our base classes and Struck's defined, we will begin to declare variables in the next video 21. Variables: Hey, guys. So what kind of data do we need for a hotel reservation system? Well, that's the variables. Therefore, so inside of our structure dress, we're going to tell you public now everything within instructors default public, but it's good to use explicit language when building your programs. So these air the member variables for our address, and they're going to be using the standard string type, and we also must include string at the top of our header file. We're standard string. So for naming our members will need a street address. City state, zip code country. Pretty basic and straightforward. And that should be good if we go into admin. Admin does not have any member variables, so we're not going to be placing anything there so we can move on to date and Date will have a whole bunch of variables, so we'll have months and you can see these written out static int January, February, March, April all the way through December, and then they return a number that basically represents that time of the year. So January will return 1 December returns 12. The struck month will use static functions, static functions of a class could be called without an object of that class. Using the scope resolution operator, static member functions are allowed to access only the static data members or other static member functions. They cannot access the non static data members or member functions of the class. So for day, we're just going to include a couple of days that we're going to use to run our example. So the dates were booking basically static into the 13th and in the 15th so returns 13 returns. 15. Basically, you could include all the days in the in the calendar that you'd like. But for our purposes right now and simplicity, we're just gonna do that. And also for struck year static and current year, which is returning 2019 or static it next year, returning 2020. So those are the only years that we would be concerned about booking for our reservation system at this time and finally for struck date. Then we can simply have our int month and day and into year, and our dates are going to be represented as the month day in year 3 13 2019 and that is all that we need for variables in each of those, so looking at double room double room will not have any variables. So weaken go to Global's and you can see our global's have already been defined with Denham's. So those are all looking good. Moving on to guest. The guest will have variables. So first we're going to include string and we're going to have to also include date that HBP for the guest. And now I'm going to place these variables under private access. So we have int guest I d. Standard sharing name day. It's okay which will have the object name, date of birth, standard string email, string sex and then a bull. His adults, you can see if we look at date here. A date has the variables month, day and year. So when we are selecting dates of birth than weaken, just immediately access the struck date rather than having Teoh put each of those month, day and year individually. So this is this is how you build out an application. Looking at hotel hotel will have variables. So for our hotel variables, the 1st 1 will have the total rooms in our hotel will give this public access so standard vector room. We can simply just call the object rooms. Then I'm going to create a protected modifier for the other variables. And protected again will mean that these set of variables will only be able to be accessed by sub classes of the hotel. So, for instance, the admin so member variables allowed only for child classes we have in tow tell a D standard string hotel name and then address hotel address you might be asking. Well, if those air protected, why is rooms public? Well, we're gonna find out later when we run our program, but for now, this should be okay. We will now go into reservation debt. HBP you also notice we're not touching any of the source files yet? We're just making all of our declarations in the header files. So reservation dot HBP We're going to start including our variables member variables. So, in booking, I d in hotel I d. We're going to have to make some includes here. So include Vector include room HBP and another thing that we're going to do here that is going to be necessary is make a forward declaration. Well, what is a forward declaration. So for a declaration is is a declaration of unidentified air for which the programmer hasn't yet given a complete definition. And so the compiler is going to need it to know certain properties of that type, but not other details like the particular value it holds or its definition. So this will be necessary again later. But I'm going to write four declaration class room, have a standard vector container of room pointers called booked rooms. I love the price, so we'll have double price payment status, status of payment. So we're going to need to include Global's that HBP. So we'll also includes more variables. A room pointer. That's what the asterisk is. Room pointer room to book. We have date. We're going to have to include date that HBP include guest dot HBP. Okay, so we have again the room pointer from the book date in date. Date out, date the gas to new guest into room number room type. We'll just name the object type into a number of guests and then standard string booking time. These are all things that would be pertinent to making a reservation. So now going to room that HBP we're going Teoh under protected access include these variables here. So a room will obviously need a room number. Correct. So we have into room number in floor number. Ah, standard vector of bed type. So the beds in the room nor to use vector. We want to make sure to include vector room type type room status status. So we'll have to also include Global's that HPV. We have variable int num guests and Max guests into numb adults into numb Children. Okay, then we have a reservation pointer called New Reservation, so we're going to have to include two things include reservation at HBP, and then we're also going to make a forward declaration to class reservation, which will be needed later for when we start writing out our functions. So what's the standard map? We'll map is a container from the standard template library that stores elements in a map fashion. Each element has a key and a value pair. So in this example, date is the key and standard string would be the value. So we need to include map to use that this map will keep track of the check in and the check out date so that we know. Hey, if this room's already checked in, we can't check into it yet. Very good. Those are all the variables we're going to need for the room. So if we go to single room or even the sweet, we don't have to write any variables because both of them being that their Children classes of room can already use the variables that we've declared in room. So that is one of the great benefits of inheritance in C plus. Plus sweet looking, good, single room looking good and that is it for variables. Okay, so to recap, when declaring variables and C plus plus know when or when not to use public, private or protected access in the next video, we will talk about her hotel reservation systems functions. 22. Functions: Creating Booking Functions: Hey guys, Now that we have our variables, we can now build functions to use them going into admin. So now we're going to create a function of book a room So Reservation Pointer Book Room four, which takes four arguments. Date dates, array. That's what the subscript operators for their then gassed registered guest room booked room int total guests. And this is our function declaration. We're going to have to include date that HBP Global's died HBP will be using. We're going to make a few four declarations. So make 24 declarations here for guest in room to see you here. That visual studio is warning us that, Hey, this function doesn't have a definition and it can also generate one for you. But we're going to go ahead now and define this in the source file. The first thing I want you to look at, you'll notice on that first line line 13 Reservation pointer Admin colon Colon Book Room, for we're not we're not just writing reservation book room, for we have to explicitly state that book room for extends from the admin class that is 100% necessary in C plus plus so we have to write Reservation pointer, admin, colon, colon book room for And then the rest of our logic, our arguments. Okay. And then we open up brackets to have our code instructions here, and you notice that there are some errors coming up with the red squiggly lines underneath it. So let's fix that first. Before I describe what the function is actually doing. Now we're going to add the function to book a room within room that HBP so a Z you see here in the admin, we have book room four. Remember, the admin is actually doing the booking of the room. This is the desk clerk. And when that takes place, the room class. We'll also have to be notified that we need to book this room. So we have a function to do. That reservation pointer is the return type. Okay, That's the type we need to return from this function. Book four date dates as an array. Guests registered guest in room number, room type, type of room into total guests. Room status, status of room. We're now going to create another function. This is a helper function to know that we booked this room, so standard string his room booked, Const. Const. Is a key word that means constant in this case. So then we declare it, and now we're going to make definitions for those functions. So we're first going. Teoh. Define is room booked. So standard string room, colon colon is room booked, const. And then bull results equals false. If status is equal to room status, occupied result equals true else. Results equals false. What we return is result, If true is yes else No, you might be looking at that last line there and saying that was a freaky looking line of code. What does that mean? Well, what you're looking at is called a turn eri operator. And it is a simplified way of writing. And if else statement So basically, the way this reads is result. That's like saying, if result, question mark means if is true. So if results equals true, then we return Yes, colon, which is else? So if results equals false, then we return No, and a turn. Eri operator is a great way to simplify your code so you don't have a bunch of additional lines of if else statements that could be otherwise written like this. So basically his room booked is either going to tell us the room is booked. Yes, or the room was not booked? No. So now we'll continue by defining the book four function. So just a sui had declared function to book room, which is going to return a reservation type. And remember, before you write the function name, don't forget to write room Colon Colon because Book four has to extend from the room class . Okay, so we've defined it and visual studio is no longer going to give us any warnings areas for that. Okay, looking back at admin dot CPP at our book room four function. This is where we're going to be calling the book four function that we had just defined in room. We need Teoh, right? Reservation pointer results equals no pointer. So we're initializing the return value that we need to get. So I like to write result. I've also seen return Val as the object name, but we essentially need to be using this variable to determine whether or not this rooms been booked. Then we're going to write the four loop arranged for loop. So auto ampersand room colon rooms, which is the total rooms in the hotel. So going back to hotel that is, this variable here rooms. Okay, so we're looping through the rooms. So auto ampersand room, which is the element within rooms. Result then equals room dot We use the dot operator to access functions within room book. For now, we pass our arguments. Dates registered. Guests booked room dot get room numbered, get room type told guests room status occupied. And then if result is not equal to no pointer than return result, that means that it's a success. The room was booked. If that result fails in his is false than we could not book our room. So you might be asking yourself what is no. PCR was no pointer. Well, that basically means, uh ah, value defined a zero. So it's It's if we have, for example, the results equaling zero, then that case is false. So we want we want that value to not be false. And in the case that it's not a no pointer than we know that we successfully booked a room . You'll notice there's some red squiggly lines under books. Room dot Get room number Get room type because we haven't declared those yet. And you might be thinking, Well, didn't you put room number? I thought I saw you put type room type in room number. Well, they're protected, so the admin class has no way of knowing where they are accessing them in C plus, plus a common way Teoh Access Member variables is through the get set pattern. So let me show you how that works. Basically, what you want to do here is in order to get your room number, you want to keep your member variable protected or private, and then create a public function in order to access it, we have int get room number, which is gonna be a constant function. And then within the brackets, we return room number. And then any time we want to be able to get our room number will use the function get, remember. And so let's do the same thing for the room type rather than an end type. It's room type is the actual return type. Get room type const return type, and then you can continue Teoh Adam for all your other variables. So in to get numb guests, Const. Will return them. Guests going back to admin, CPP. Now everything is being correctly recognized. Very good. So these are all ways to get your member variables. Well, if you can get them, you can also set them to a value. And we can do that by creating voids methods so you can write void set room number, which takes into argument and then in the brackets, have the room number variable be equal to number. That you're passing is an argument, and that way you'll be able to set your variables if you need to in other classes or struck's, And you could do that for the room type the room status, the number of guests. Those are functions for room. We need to include also gassed HBP and date HBP at the top for headers. Okay, we will come back to the book for function to define it further, because that will be essential 23. Functions: Creating Date Functions, Operator Overloading: So now let's go to date that HBP So we have already included functions we need for year, day, month. Let's go ahead and complete some for the date. So the date will I need a default constructor which is going to initialize month day in year. And for now we can initialize them each a zero just as we have done in the other constructors that we had. We're going to include a second constructor that takes month, day and years arguments. And this also has the explicit keyword in front of it. So this constructor, which takes three arguments, will then initialize month day in year. Okay, just a zwei had done for previous examples. We will need some more stuff for the date. We're going to include a function called is valid because we need to be able to determine whether or not our date is valid and the data within it is valid. So of bull is valid. Const And we're going Teoh, define this here directly in the header. We don't have to do this in a source return month not equal to zero. So this symbol, with the exclamation point in the equal symbol that means not equal to in C plus plus. So this reads month not equal to zero, and then you see the double ampersand. This means end. So this reads month is not equal to zero, and day is not equal to zero, and year is equal to 2019. Then you see these two lines and parallel. This means or so year is equal to 2019 or years equal to 2020. He that was a lot of symbols. Well, there are a lot of different types of operators in C plus. Plus, these are a few that you should know right off the bat. Pretty straightforward to understand. But essentially what this function is doing is it's making sure that we don't have ridiculous numbers representing months. So this function being that we defined it here in the Header file, it is also an in line function, and the way it's written now it's called implicitly in line, but you can actually include the online keyword before bull to make it explicitly in line, so this would be an example of an inland function. Now, another important thing here is that your operators, just a zai had shown you with not equal equal. These operators can be overloaded in C plus plus, meaning that every time that they're called and used, you can have a certain set of statements or functions. I get executed, and sometimes it is absolutely necessary to do so. If you're gonna be using your user defined type using the standard template library. And so in date we're going toe overload the equals operator for equality when basically comparing the date to other instances of it. So bull operator equals so equals equals const. Date ampersand other. So this is a representation of what's called passed by reference to CONST. Then we have the constant you ward and we open up a block here and we return month equals other dot, month and day equals other dot, day and year equals other dot year. So if this is starting to throw you off a little bit, don't worry. We're almost finished with this part. We'll get back to the writing of functions. This is going to be necessary, being that we're using the standard template library for date. So I have to also include to overload the less than operator, particularly for use with the map. Standard map Again, The map can be found here in room HBP. Sobule operator Less than constant eight ampersand. Other inside of the bull for operator less than we have. If month is not equal to other down month, then we return Month is last sign other dot month else. If day is not equal to other dot day, then return day is less another dot day else. If year is not equal to other die year return year is less than other die year else returned. False Good. We're done overloading our operators fun times, so it won't always be 100% necessary to do that. But it is also really great to become familiar with overloading operators because they can obviously be very helpful in reducing the complexity of your program. So that is everything that we're going to need for our date header 24. Finalizing Constructors: so starting in addressed, I teach PP. Let's include a few constructors. So we have our default constructor and we will simply implemented here in the header. And then we're going to create a second constructor that will pass five arguments And what we're going to do is we're going to initialize or variables this way. So let me show you how that's done. So for the arguments, we have standard string underscore street address so that we can distinguish it from the member variable called Street Address. And we've done that for each of the member variables, all five of them. And now you can see that I have a bracket to implement the constructor. How do we ate now? Initialize these with the members. Well, you could do it here and write them out. But the easier way to do it and a common way to do it is after the end of the parentheses. Place a colon and then type your variable. So street address, okay, and then in parentheses is you now want a place, that argument that matches it. So we're going to do that for each of them. So as you can see street address. Underscore street address city underscore city, state underscore state zip code underscore zip code So on and so forth. So you can see that they are being initialized in the same order that they've been declared in the header. So that is how you would initialize variables in a constructor from constructor arguments. So in room H plus plus, first, we're going to finish reading out the constructors for the room so we can have a default constructor. So we're going Teoh, create a second constructor that takes two arguments here so that we can create a room from a room number and a room tight. So kind of like I showed you before in the address trucked with initializing variables we have in room number, room type, type of room, then colon. Now we can set the room number variable to initialize from the room number argument, OK, and I'm even initializing other variables. You can you can initialize any variables you want, even if they're not a part of the arguments that are listed. So I have status by default. A room will be vacant and I also set Max guests here to six no more than six people would be allowed in any given room, and I included brackets, which means that it has been defined in line in the header file. So now if we go to double room, we're going to need to include another constructor here that will simply take one argument , which is the room number. So then, if we open up brackets, we can then initialize variables, so room number will be equal to underscore room number. And you might be thinking, Hey, I don't see room number anywhere on this page. Well, that's because it's being inherited from the room class, as we had shown in previous video. So room number equals underscore room number beds, which is the vector container dot pushback bed type. Double push back is a way of adding a new element to the vector container. Being that it's a double room, we're going to go ahead and add two double beds because that seems that seems appropriate for room like that, and we know then the type is double room type double and by default status is that it's vacant. Nobody staying there. We can leave the source file alone. Now we will go to guest dot HBP and we have our constructor. Destructor will have another constructor here that's gonna take six arguments. I'm gonna show you hear a constructor declaration that we'll then define in the source files, since we have been defining a lot of them directly in the header. So this is another way of doing it. So this constructor in question is going to have guest I d. Guess Name, date of birth, email, sex. Whether or not this guest is an adult, okay, like we were doing with initializing are variables in constructors. Rather than defining it directly, we will add a semi colon at the end of it in the header and then in the guest source file, we will define it. And this is all were definition for that second constructor. Okay, objects to delete. And it's initializing each of the member variables that we had declared earlier, using arguments of that constructor going down the list and also listen them in the exact same order that we declared the men in the header file. Now is it 100% necessary to do it that way? No, but it is good practice to do so, so That's the second constructor that we're gonna have for a guest. Uh, now we need to go the reservation, so we'll go to reservation that HBP. So this is a constructor Destructor. And as you can see here, we can do getters and centers for the variables, just as we had done in room or any other class payment status. Get payment status. Constant return payment status void. Set payment status with the argument payment status. Object name underscore Payment status. So then status. A payment is equal to underscore payment status. We also need to include string here. We're going to be using that for the reservation class and we're going to create a second constructor here that has seven arguments within it. So reservation with these arguments. So of room pointer, room to book date in date, The out date new guests, which is the guest that's going to be rested on the docket into room number. They're staying in room types of the type of room and number of guests. So is it one person, five people and then we initialize them to the member variables within the class that have already been declared just a We had done in other examples. Now, inside of the brackets here we've added another piece of logic. So as long as if room to book is not equal to annul Pointer book two rooms dot pushback room to book. So that means we booked the room. So let's add it to our array of booked rooms were going to be using that specific constructor In order to make a reservation. We can leave reservation dot CPP alone. Of course, this is the constructor, so objects to initialize. This is the destructor objects to delete, so the reservation looks pretty good. Let's click on single room and, yes, single room. We'll need another constructor. So inside of single room, we have a single default constructor and then a constructor that takes one argument so single room and underscore room number. Then we can initialize there Variables for it. Room number equals underscored room number beds dot pushback bed type single because it's a single room tape will then equal room type single simple enough single room source again. We don't have to do anything further with it right now. If we set up the single room in the double room to have constructors that take a room number is an argument that we're going to do the same thing for sweet, since it also is derived from the room class. So this is our destructor, her default constructor up here and then the constructor. That takes one argument sweet and under sort room number. Then room number equals underscore room number. And this is a sweet. So we're gonna soup it up with some beds here. So we'll push back King bed will to king beds and then beds that pushback queen beds dot push back a second queen. The type, of course, is room type. Sweet in the status is vacant. And, I don't know, maybe maybe that's not enough beds for a sweet. Maybe we need to throw in a few more, but you got you kind of get the idea. The sweet source will not need any further action objects to initialize objects to delete. Okay, 25. Functions: Finalizing Booking Functions: So now if we go back to the admin where we had book room for, you'll recall that we called a function from room called Book for and we have not put any logic and a yet. So let's go ahead and go to room room, Dad CPP and let's write out our book for function. First thing we want to do is you want to include Io Stream at the top because we're going to be printing out values your counsel, then inside of book for the first thing you want to do is write, if not dates. Zero dot is valid or not, dates one dot is valid. Return no pointer. And what this means is, if there are no day, it's then early out from the function. And early out simply means don't go any further. Get out before it's too late. If you basically are running a program and you come across invalid data, you want early out. Otherwise you could cause a stall or crash to the program. And so that's the first thing we want to do for book for Don't to make sure that dates aren't already booked. So four and in visual studio. This is kind of a neat thing. Whenever you're right, for if you tap the tab key, it will automatically create a four loop for you. So it's really convenient. So I create are four loop. We're going to change values and expressions, so int I equals zero. So in order to loop through our dates array, we're gonna have to write this, and it might seem confusing, but bear with me here. So I is less than or equal to size of dates divided by size, of who's divide my size of dates Index zero, and then I plus plus. And that is what's going to allow us to be able to loop through our dates array. So now if reserve dates dot find dates, I is not equal to reserved dates dot end, then return null pointer. So that means the room is reserved on this date. So this room is unavailable, so reserve dates is the map we're using. And basically what it is doing is it's searching through all the reserve dates of that map , and if it's found that either the check in or the check out date is there, then we have to return. No pointer. No way. No, we can't. We can't run this This booking, it's not gonna work. So if if none of all that turns out to be true, then the room is currently vacant. So now reserve this room four requested dates. Okay, so date start Did is equal to dates at index zero in date. Indeed is equal to dates at index one. Okay, we could just do it by assignment here. Now we want to update the room status so we can write set numb guests to be total guests, which is one of the arguments that were passing from the function here. Right. Total guests and set room status two. Status of room. Because now it's gonna be occupied. It's no longer vacant. Good. So now we want to create a new reservation. So new reservation, which is declared here in the header okay, is going to be equal to new cured reservation. So we're calling the constructor, and the first element is basically appointed a room. So we have to write. Is this because we're in the room class? So this comma then start deep than nd a registered guest room number type of room total guests, and that's it. So now we're going to insert our dates into our map. So reserved dates dot insert. And in order to do that, we have to write standard make pair start date, and then we'll call that check in. As the value reserve dates dot insert standard make pair and dates, which will call, check out and the insert standard make pair functions. These all come from the standard library of C plus plus. Now we're going to go ahead and print our dates for a consul. So I'm going to do this. This is done through an iterated er so I will write auto. It equals reserved dates dot begin. So that starts at the beginning of the container. Then it not equal to reserve Yates dot end. So the end of the container. So we're iterating all the way through it. Here it plus plus. Now I'm going to write the logic to print it. You don't have to have this memorized. It could be confusing. So standard see out its first dot month. This is just so that we're gonna be able Teoh see it in the consul when we run the application we're gonna separate him with. Backslash is here and then it first that day it first die year it second and then standard and line, standard and line, and that will allow us to print our dates out. Now we simply need to return our reservation. So return new reservation semicolon and that's it. Excellent. That is how we will book a room and that is it for all of the functions that we're going to need. Teoh run our hotel reservation system. So, to recap, you should have a basic understanding of how functions air declared and define and C plus plus if they compile and run. Then you succeeded in the next video. We're finally going to book guests into our hotel. 26. Conclusion: Let's Book a Guest!: Hey guys. So we finally reached the end of our Siri's and I think we've covered everything that we need. We have our classes or variables and our functions. And so now we contest to see whether we can book a guest or not. So before we go into main dot CPP, we're going to go into admin dot CPP and in the constructor, we're going to populate our hotel with rooms because we have not done that yet. So we're using the rooms vector container that is present inside of hotel. And just for the sake of simplicity, we're going to put three rooms in our hotel, so rooms don't push back room room 2 41 is a single room rooms dot pushback room 105 which would be a double room rooms that push back room 1 15 which will be a single room. So that way we can choose one of those when we decided to book a guest. So now, going into Maine that CBP we need to include date that HBP guess start HBP we will need to include admin died HVB and that should be it for our include directives. So now we need to ask the question, What dates are we staying for? So date check in which will be the object name equals date, and we could just use numbers here. So let's say we want to stay June 23rd so six, 23 2019. And that's perfectly fine for a date. However, if you recall, we have specific months and days and even years already specified in our date header. So instead of writing numbers will write month and then extend to June. Okay, And let's say we're going to stay for the 13th as far as check in and then year current year. And we need to remember to include parentheses after 13 just like that. So that would be a better way to write dates because it prevents us from making any errors for the data. So day check out equals date months of June and we'll check out on the 15th of year current year 2019. Okay, we have one too many of parentheses. Okay, so those are the dates that were staying for now, we're going to create an array four or dates and add the check in and check out day is to it. So date dates with two elements equals in brackets. Check in comma. Check out. That's our dates array. Now we will set up a guest guest. New guest equals guest with the following arguments. So we have the first argument as the guest I d. Which could be any sort of number. That's for the purpose of the hotel system. So I'm just randomly using 746592 Then the name of the guest, Jim Sherman, for example, the date of birth of the guest. So we have the date of February 25th 1965 email the sex male. And then is this Guess an adult said too true. So that's our new guest for our room. Okay, so now we will have the desk clerk book a hotel room for the given dates. We will call book room for in the admin class with the DOT operator. So we need to have admin, which will call desk clerk. Okay. Desk clerk dot book room for. And then we will pass dates the new guest, then desk clerk die rooms at zero total number of guests. One. So desk clerk dot rooms would be the rooms vector container that we just used to populate our hotel with. Right. So, room to 41 the 1st 1 that we pushed back would be at index zero, room 105 at index one and room 1 15 index to and again, that is, inside of hotel. So, in order to access in index within that array we use at So we're going to book gym for room 2 41 which is a single room being that he's on his own. Okay, now we will print Yes, if the room was booked or no, if it was not standard See outs. Desk clerk dot rooms dot at zero dot Is room booked standard and line. And we'll add another space here, so standard in line again. So remember, this is room at index zero. So, room to 41 Is it booked or not? Great. So that's all we need to know whether or not we can book a room. So now, in the solution Explorer in the right column, we're going to right click reservation system and left click rebuild, and that will build out your program. So give it a few moments and it is succeeded. Very good. So once that is finished, we can run a program. And we do that by pressing F five. So do that. And it's a success. Yes. So for June 13th 2019 we have checked in June 15th 2019. We've checked out. And yes, the room has been booked. And the last thing you will see here is this line that says that the process 9164 exited with code zero. That means that the program was successful. Remember, in in Maine we return zero at the end. So success code zero means that your program executed without years we have successfully built a very simple program. Teoh handle a hotel reservation system using built in types and user defined types and C plus plus. So at this point, we should be able to compile, build and run or application booking a room for a guest. It is a really simple and easy way to start out by building c++ applications, and I think that it was a really good example of how to use the C plus plus language. So where can you go from here? Well, you can start planning your own applications, you will learn a lot. If you focus and dedicate your time to building applications, it can be very difficult to learn how to program. So the best piece of advice that I can give is to do your best to learn new things. Always be learning new things, no matter how difficult it. Maybe if you put in the effort the time, the hard work, eventually it will pay off and you will know what you're doing. And then who knows? Someday you might be able to share it or teach it to other people. I want to thank you for sticking with this tutorial. Siri's. I hope that you learn something about C plus plus classes, variables, functions and even planning and software engineering. If you have questions, then feel free to ask. I am here to help so fire away. Thank you again. I am Robert Slattery and I hope to see on the next class goodbye