 Hello and welcome back. In this lecture, we are going to see an example C++ program that uses most of the features of C++ programs that we have learned so far. Here is a quick recap of some of the various features that we have learned so far in the structure of a simple C++ program. We have looked at variables and type declarations, assignment statements with arithmetic and logical expressions. We have looked at sequential execution of statements, conditional execution of statements using both if else statements and switch case statements and we have also looked at conditional expressions. In this lecture, we will try to put all of this together to write a simple yet intelligent version of the fortune program that we already saw in a previous lecture. So, here is a specification of a slightly intelligent fortune program. So, this program is going to take date and time as integer inputs in this format. The date as date month here format and the time as our minute format. It will first do a check for invalid date and time. If the inputs are valid, if the input date and time are valid, it will output one of these three messages. Good morning, good afternoon or good evening depending on the time of the day and after that it is going to print one of three predetermined fortune messages. So, we want to write a C++ program using whatever we have studied so far that has this functionality. So, let us see how we might go about doing this. So, here is a simple flowchart for checking the validity of date. We can read the inputs date and date month here format and time in our minute format and then from the date that is read, we can compute the calendar date part of it which is just the 2 digit date part of it, the calendar month part of it, the 2 digit m part of it and the calendar year part of it which is the 4 digit year component of the date. Now, once we have computed these three things in some manner which we will see in a couple of slides. We then want to check if the calendar date lies between 1 and 31, if the calendar month lies between 1 and 12 and if the calendar year is sometime at present or in the future. So, let us say if the calendar year is greater than equal to 2014 and notice the use of the double ampersand operators here and if you recall, this is the logical and operation when constructing logical expressions in C++. If the answer to this question whether the three conditions are satisfied is yes, then we have a valid date input otherwise we do not have a valid date input. So, we simply output bad date input and return control back to the caller. So, here is how we might write it in C++. As I show you how this code gets written, I am going to fade out some parts of the code which I will not be focusing and then I am going to show in darker color and clearer font the other part of the code in which I am going to be focusing. So, here we have this int main function, it is a main function which returns an int value. The actual code inside the main function comes within this pair of matching braces. There is a return 0 at the end of it and we are currently writing the code for checking the validity of date in C++. So, additional code comes here to implement the remaining functionality of our intelligent fortune program. So, we must start the program with the declaration of the different variables that we need. Here we need only integer variables date, time, calendar year, calendar date and time, calendar date, calendar time, similarly hour, minute and a hash value. These three things are going to be used in a later part of the program. Next, we output this message give date in the date month year format and time and hour minute format and then we read in the date and time and here I have inserted a comment to show how a date and time that is read in is going to be processed later on. So, this comment as you will recall is not processed by the C compiler but it may be very useful to tell the reader of this program how the logic of this program works. So, let us say that date that we have read in is 27 July 2014 and let us say the time is 145 p.m. So, the next thing that we are going to do is we are going to extract the calendar year from the date that we have read in. Now, given an integer like this, if we take its remainder when divided by 10 raise to 4, we will get the last 4 digits which is the year. So, that is what I have done here using the percent or the remainder operator and the quotient will be the date and month part of it. So, for example, if this was my input and if I divide it and I obtain the quotient, I would get 2207. Now, from this date and month, I want to extract the month which is the remainder when I divide it by 100 the last 2 digits and similarly the date part of it is the quotient on dividing by 100 which are the first 2 digits. So, this is how I am going to extract the calendar year, calendar month and calendar date from the date that has been read in. So, notice I am using different kinds of arithmetic operations here. So, these are arithmetic expressions as we have studied and these are assignment statements that are executed in sequence. After I have calculated these quantities, I can now do my check if the calendar date is greater than 31 or less than 1, if the calendar month is less than 1 or greater than 12 or if the calendar year is less than 2014. Notice I am building a logical expression here using this double bar operator which is the logical OR operator. So, if any of these conditions evaluates to true, then the logical OR of them evaluates to true and then I output bad date input, print an end of line and return control back to the caller with a return value of minus 1. So, notice that I have used minus 1 here and 0 here, this is because when I return from here the caller can perhaps figure out from the return value that something wrong happened whereas here everything went right. Now, how are you going to check the validity of time? So, just like for the date case from the time in the hour minute format that we have read in, we are going to compute the hour in the minute part separately and we are going to check whether the hour lies between 0 and 23 and the minute lies between 0 and 59. If so, we have got a valid time input otherwise we are going to output bad time input and return control back to the caller. So, this is how we are going to do it in the program. Notice I have hidden the declarations and code for checking validity of date because we have already seen that we are now focusing on this, we calculate the hour and the minute by basically dividing by 100 and calculating the remainder. And as an running example provided within comments at the time was 1345, then I get the hour is 13 on dividing by 100 and taking the quotient and I get the minute as 45 on taking the remainder on dividing by 100. And then I perform this check, if hour is less than 0 or greater than 23, if minute is less than 0 or greater than 59, I say bad time input, print an end of line and again return minus 1 to tell the caller that something bad has happened. What do we do after that? We are going to print a greeting and this greeting is time dependent. So, we check whether the hour is between 6 and 12, if so, we print good morning. Otherwise, if the hour is between 12 and 18, which is between noon and 6 p.m. we print good afternoon and in all other cases we print good evening. This is how we print our time dependent greeting and how do we finally print the fortune message? This we have already seen in an earlier lecture, we calculate a hash value which lies between 0, 1 and 2 from the given date and time values. Then we use a switch case statement and depending on the value of the hash, we print out one of these three fortune messages that we had already seen in an earlier lecture. So, this constitutes our entire intelligent fortune program. In summary, we were able to write a simple yet interesting program that used integer variables, assignment statement with arithmetic expressions, logical expressions were used in the conditions of if statements. We sequentially executed the different statements in the program, we also used conditional execution using both if else and switch case constructs and for if else we also saw nested if else statements and finally, we saw the use of C in and C out for reading inputs from the keyboard and printing output back onto the screen. Thank you.