1 / 25

Unit 3

Unit 3. Introduction to Visual Studio Examine the Rocket problem modelled in C# Learn to make small changes to a C# program. A Programming Language Used to represent models developed from problems in the real world This is the world of the class , the object, the method , etc.

atara
Download Presentation

Unit 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit 3 • Introduction to Visual Studio • Examine the Rocket problem modelled in C# • Learn to make small changes to a C# program Learning to Program with C# - 3

  2. A Programming Language Used to represent models developed from problems in the real world This is the world of the class, the object, the method, etc. A Programming Environment a tool used to enable us to manipulate models developed in a range of programming languages manages all the administrative requirements to make the programs run C# vs. Visual Studio (VS) Learning to Program with C# - 3

  3. Remember purpose at this stage: • Aiming to gain minimum knowledge and skills in C# & Visual Studio • enough to get an appreciation of programming only • C# and VS are very complex tools • in the following, aim to ignore the detail… • … just follow what we're suggesting for now • Watch what I'm doing… • you'll have a chance to practice and explore later, with these slides to hand Learning to Program with C# - 3

  4. A reminder about programming languages first • Rocket model consists of • a number of objects… • … that communicate with one another and change over time • All this described using a textual language • some imagination required to bring the flat text to life Learning to Program with C# - 3

  5. Need for a Prog. Environment • We could write the entire text describing a problem in a single file, but… • can't share/reuse parts of the file • would be like requiring a different wooden spoon for every cookery recipe that required one • can't update one part in isolation from others • … so the text is broken into pieces, and can be shared around • The prog. env. is required to manage all these pieces appropriately • It is a kind of complex word processor, for programming language text files Learning to Program with C# - 3

  6. Fundamental process… • Using the programming environment… • we enter a description of the solution to our problem • some of it is new text • some specifies existing classes/methods etc • the programming environment checks that our description matches language rules • if it does not, we edit it and try again • with a successful check, we can execute our solution • the classes, objects etc come to life, modelling whatever was in our description • sometimes we don't get what we expected – we need to go back and rework our solution Learning to Program with C# - 3

  7. Visual Studio basics • VS organises problems using Solutions & Projects • A Solution solves a major problem area • it may consist of a number of smaller, stand-alone, problems • each of these is represented using a project • these individual project components may be set up for reuse in other solutions • Remember – VS created for large applications • here, we will primarily be concentrating on Solutions that contain just a single project • concentrate for now on the concept of a project Learning to Program with C# - 3

  8. Exploring: the Rocketry project • Open the Rocketry.sln file • Having opened up the project/solution… • Don't panic! • The screen contains a lot of information, but it is well organised • There are fundamentally two views available through the environment • The C# view of classes, objects etc. • The Visual Studio view of solutions, projects, files etc Learning to Program with C# - 3

  9. The Object Browser • This is the C# view • Views C# items available in this solution • Key one here is the project Rocketry • Press on the + symbol to find out more about the project • We'll address the others later Learning to Program with C# - 3

  10. Visual Studio views Solution Explorer shows the various files required in order to make up the complete solution Class Explorer is a quick way to find a required textual description, of a class or method say It's hiding behind the little icon tab above the Solution Explorer tab Solution & Class explorer Learning to Program with C# - 3

  11. Supporting the process… • Various tabbed windows at the bottom of the screen, they'll concern us more later • Task List keeps track of tasks that must be performed to get your program to work • Output displays output from the various processes taking place • Other tabs appear here periodically Learning to Program with C# - 3

  12. Click on + next to Rocketry, then on + of Rockets to open them Rockets is a namespace our place to keep the various C# components making up the project Listed here are the major C# components of our rocket model Rocket, RocketController and Arena you'll recognise from the last unit Back to the Browser – let's explore Learning to Program with C# - 3

  13. Experiment… • Move the mouse over the small icons • a short description of the item pops up • some of them are classes, remember them? • others are interfaces, we'll talk about them soon • Single click on an item • what happens at bottom & right panes? • members (remember them?) of the item appear in the right pane • a longer description of the item appears in the lower pane • you can explore the members in just the same way • do you recognise some of them from the previous unit – TurnRight, Coast, IncThrustLevel in the Rocket, for example? Learning to Program with C# - 3

  14. Double click on the class RocketController a new window appears, covering the browser use the tab to switch them this text describes how to create instances of rocket controllers – remember, this is what a class is for scroll around if you wish then close it using the little cross next to the Solution Explorer tab you should have just the Browser again Exploring the textual description Learning to Program with C# - 3

  15. This time double click on Fly in the members window when RocketController is selected in the left pane You are taken directly to the text opposite This is the sequence of instructions that will fly the rocket Each one is executed in turn Final one keeps window open How do you predict the rocket will fly? Exploring the Fly method Learning to Program with C# - 3

  16. Choose Start from Debug menu VS will do some preparatory work, and then an Animation window should appear, with the rocket in it impressive graphics, eh? When the rocket has landed, remove the window by clicking the close box Did it fly as you expected? Do you agree that it flew according to the instructions contained in the Fly method? If not, run the program again, as above Running the rocket simulation Learning to Program with C# - 3

  17. Ignoring complexity… • Huge behind-the-scenes activity to make the rocket fly, but • we were only interested in the Fly method • just 10 lines of code • thousands or even millions of lines of code were probably executed for the whole simulation!! • it is important to be able to ignore all the complexity that surrounds you at this stage • compare with any complex machine in your environment • e.g. video recorder – you don't care about the inner complexity of the machine, just as long as it records your favourite program at the right time • for now we're going to experiment with Fly Learning to Program with C# - 3

  18. Making a change to a program • We're going to adjust the rocket's flight • by making a change to the Fly method • find it again in Visual Studio • We'll fly off the left edge of the arena • consider what instructions might be required • need to take off, head left and just keep on going • remember the model – thrust/attitude settings only have an effect when you use Coast to give them time to operate Learning to Program with C# - 3

  19. Making the change • Simply edit the instructions to get the effect you want. Something like: Rocket.EnginesOn(); Rocket.IncThrustLevel( 60 ); Rocket.Coast( 1 ); Rocket.TurnLeft( 90 ); Rocket.Coast( 10 ); • You must use exactly the right syntax: • Names of methods matching those seen in the object browser, correct use of brackets and semicolons – just as above Learning to Program with C# - 3

  20. To run your new version: • Visual Studio must check that your new flight description is legal C# code • Choose Start in Debug menu again • This automatically saves & checks your new code before trying to run it • If you have made no errors, it will run • did it do what you expected? • feel free to experiment some more • If you have made an error, read on… Learning to Program with C# - 3

  21. Detecting & correcting errors • [if you made no error, introduce one • say, remove a bracket from one of the instructions] • When you try to run the program… • VS tells you there were build errors, asking you if you want to continue • Do NOT continue! Click 'no' • The Task List window pops up showing you the errors the system found • Read the first error, then double click on it – you will be taken to the line in the code • If you can see what is wrong, fix it and try again Learning to Program with C# - 3

  22. Deciphering error messages • Error messages are sometimes perfect… • try removing just one semi-colon • …but not always… • particularly for beginners using an industrial-strength prog. environment • and also because entirely accurate reporting is a highly skilful task, beyond a mere computer • try removing a bracket • Finding the cause of the reported error is one of the skills to learn • First, see if the message helps you. It may – but don't slavishly follow it, if it seems wrong • If it didn't help, look very carefully in the vicinity of the reported error – can you see anything amiss? Learning to Program with C# - 3

  23. Now experiment….! • Make changes to the flight of the rocket • to get used to the edit/rebuild/rerun process • Make some changes that you know aren't correct syntactically • to get practice at understanding the errors that are reported, and at fixing them • notice that sometimes, one real error may cause two, three or more error reports – if you really can't see what's wrong and you've fixed an error, try rebuilding it again Learning to Program with C# - 3

  24. Reflect: what have we been doing? • Imagine you were a rocket scientist! • You've just been tinkering with your rocket controller for each new test flight • Notice that each time you tried out a new flight plan, you threw away the old one • [to be precise you deleted or wrote over it] • This is one way to adjust the behaviour of programs • simply replace the old behaviour with the new, by overwriting the old code with new code • the old behaviour is discarded • This is fine when developing a program Learning to Program with C# - 3

  25. Summary • Contrasted C# with Visual Studio • Introduced a minimum set of Visual Studio commands to get going • Experimented with the solution to the Rocket problem in Visual Studio • Learned how to make destructive updates to a program • old behaviour is lost • ideal when developing programs • Next unit considers constructive updates • when we wish to keep both the old & the new Learning to Program with C# - 3

More Related