All right, so this will just throw some data in there because I just want to see it work. And I'm just throwing in an i. So no big deal. So now, I read the data from the file. I create the array based on the size that the user tells me. I read the data from the file. And then it says pass the arrays to your reverse function and then print out the reverse information one value per line.
So I'm going to come down here, then. And I'm going to call the method. And so the method, what do we call that, reverse? Reverse. So reverse. And I'm going to send it my array. And I'm also going to send it the size, which is n, right?
Now the array, or the function, is going to give me back a pointer to the reversed array. So this is, I'm going to say, int pointer. And then I'm going to call it-- yeah, I don't want to call it flipped because I did that in the main. I could use flipped again, no problem because it's a different scope. Scope is curly brace to curly brace plus the header.
But I'm going to call this backwards, just to make sure that there's no confusion. So this is going to send my array to the method with the size. It's going to give me back a pointer to the new array that was created in there.
So then, I'm going to pop over here, and I'm going to say four. And I want display. So int, and then the length is going to be n. And I'm going to show, line by line, so c:out, I'm going to show backwards at position I on its own line, which means I need to do an indel.
And then, backwards was created as an array in memory. So I need to clean up my memory. So I need to delete the array at backwards. And again, if you don't do the delete, we did a new. If you don't do the delete, then it will be a memory leak. And then I also need to clean up my array because I also used a new keyword here. So I need to delete that array as well. So I'm going to say delete array, my array, semicolon, like that.
So that just cleans up the memory. All right, let's see if I have any bugs. If I have any bugs, we just fix it. No big deal.
All right, how many numbers to read? Let's return numbers. Now you notice it goes nine down to zero so that's perfect. Because we wrote into the file like this, just going to 012345. So I read 10 numbers, and then it's now backwards. So that's beautiful. All right.
So let's see how we did. I'm going to do a Control-A. Control-A selects everything. Control-C copies. Now I'm going to pop over here. And then I'm going to do a Control-V to paste. Oh, I've go to Delete this code. So I'm going to delete this right here because those are just the instructions.
And then I also need to delete this right here because the file has already assumed that the data file already exists. So you already have a data file. So this right here, I just want to make my code work. So I want to go ahead and delete that as well.
So I get the size. And then I flip it. And then pause, I did this to pause my application. But I'm going to pull that off because they don't want it on there. They don't want the pause down at the very bottom. That's no big deal.
So let's see. Everything else looks good. All right. So now I'm going to hit submit. All right. Got an issue. It says, it looked at the output, and the standard output is not what was expected. It says click here for more details. All right, let's find out what they're after.
So this is what they're expecting to come out-- six, five, four, three two one. But instead, what they saw was how many items do you want and then six, five, four, three two one like that. So they don't want the prompt, apparently.
Let's look at the instructions real quick. Prompts and output labels. There are no prompts for the integer. Got it. All right, we can fix that no problem. And then, if the integer read in from the standard input exceeds 50, then the program should terminate silently. I didn't do that. So let's see. We get the number here. If it exceeds 50, or if it's less than zero-- so here, I'm going to say if n is less than zero, or, remember, that's how we say or in our C-based languages, C+ Java, C#, pipe pipe is or.
Or if n is greater than 50, then we need to terminate prop silently. So terminating silently means don't tell the user. Just close the application. So I'm going to return a negative 1. If you return a 0, and, really, I should return a 0 down at the bottom. Let me go ahead and return 0.
If you return a 0. The main wants to have an int. So we want to return something because this method needs have a return. If I return a 0, I'm telling the environment that everything went well. If something went wrong, I want to return a negative 1. So here, something went wrong, So I want to return negative 1.
So here, I'm going to terminate silently with error. And by returning a negative 1, you're telling the environment that something went wrong. And the reason you want to do that is because, oftentimes, what we do in software development is, we launch our program. And then our program launches this program, that program, this program, and this program.
And if one of those programs fails to launch properly, then we need to look for the environment variable. And if it's a negative 1, then there's no reason to launch the rest of the programs, or the rest of the components, because if one component fails, our program is not going to work because we need to have all those items running.
So, for example, if you're GSP, and you're creating a game, and you hit the graphics card, and the graphics card is a motherboard graphics built in to the motherboard, well, that can't play games. It can't play powerful games, I should say. So therefore, if we cannot instantiate our graphics card, then there's no reason the to launch the game.
So instead, you just pop open a dialogue box that says error, your graphics card is not compatible with this game. go. Out and spend a couple bucks on a graphics card. So if you're an electronics major, then you need to be hitting your sensors and seeing if your sensors are working. And if you hit a sensor, and it gives you back an error, meaning that the sensor is failing, or the sensor failed and was not able to be initialized properly, then guess what? There's no reason to run your application if your sensor doesn't work. So pop open an error message. And this says, you know, your sensor doesn't work. That type of thing.
If you are a business software developer, and you want to hit your database, and you try and hit that database, and, guess what, the database fails to open-- maybe it's closed down for maintenance or something like this-- then why are you going to launch your application if you can't hit your database? So you just pop up an error message and just say, database is not available. And then the application just shuts down. So you want to have your application return negative 1 if something goes wrong, or an error code, something like this. You return a 0 if everything's good.
So with this right here, I do my deletes. This terminates silently. That's good. All right, let's run it again.
Oh, and then, also it was saying that we should not have a prompt. You see that? So let me go make sure I pulled off my prompt. So here, I asked the user how many numbers to read. But it wants us to not prompt for the number. So I can do that. I'll just pull off my prompt. OK?
So now, what it's going to do is, over here, if I pull off my prompt here, like this-- and, let's see, what else did I change? Oh, I did my if. So if the number is bad. So here I'm going to say, if n is less than 0, or n is greater than 50, then we want to return a negative 1. That's going to terminate it silently. Terminate silently.
So now, if I run this, this is what it's going to look like. It just pops. You see that? So if we put in 10, like that, then it's going to show those 10 values like that. So there's no prompt. And that's what they're asking for. So that's what we'll give them. No big deal. All right, so let me hit cement. There you go. OK? So that's how it's done.
[End of Audio]