You won't learn all of QBASIC, but just enough where you can write address books and records and things like that. then your programs would have no point. Programs can be written and. The goal of our study is to learn how to write computer programs in QBASIC. Write following expressions in appropriate. In this lab we will go through the programming process to write a few simple programs in QBasic. (Coding): Now we write the algorithm in QBasic. Do you think you could help me write some Qbasic statements? I have a final due tomorrow and i am so lost! Reply Delete. QBasic programs. These are some old QBasic programs I had. Its output is executable QBasic. On Unix you can use something like 'a' and 'image' to write. Computer Programming With QBASIC. of games and other executable programs using QBASIC. Screen and then you are set to write your fist program in QBASIC. . QBASIC might not write anything to the. then it's time to make up some of your own programs. QBASIC's help is what you should read through whenever you are. Introduction to QBasic. Intoroduction to QBasic. Programming is a process that. The first step in. The programmer then proceeds to design. At this point (and not before!) the programmer. In this lab we will go through the programming. QBasic. Problem #1 Write a program than converts a Fahrenheit. Celsius temperature. Understanding the Problem. This problem is fairly straightforward - -- the program will need to. Celsius temperature. Designing the Algorithm. The basic steps in this program (and in many of our other simple. Fahrenheit temperature)perform the calculations (in. Celsius temperature)print the results (print the. Celsius temperature)The only part of this. Fahrenheit. temperatures to Celsius. Sometimes, as is the case here, there are. In this case, we know there is a formula for. Fahrenheit to Celsius. It is. C = 5/9(F - 3. Translating the. Algorithm into QBasic (Coding): Now we write the algorithm in. QBasic. Getting the input is done using an INPUT statement. PRINT statement. The Fahrenheit and Celsius temperatures need. Ftemp as the variable for the Fahrenheit. Ctemp for the Celsius temperature. The complete. program (including REM statements for documentation) is as follows. REM Temperature Conversion. REM Programmer's name (you should put your name here). REM This program converts Fahrenheit temperatures to Celsius. INPUT "Please enter the Fahrenheit temperature: ",Ftemp. Ctemp = 5/9*(Ftemp - 3. PRINT "The Celsius temperature is "; Ctemp; " degrees.". Now the program is ready to be. Using QBasic- -- > Log into the. Computer Science option from the. Roanoke College Main Menu, then select Quick. Basic from the. Computer Science menu. You should now see a. Choose the option of getting rid of the. ESC key) and you will be in a window ready to type in. Type in the. temperature conversion program as written above (put your name. If you make mistakes and need to. You may notice that after you type a line sometimes what you type. QBasic automatically puts all keywords (such as REM, INPUT. PRINT, and END) in upper case letters no matter how you type them. It. leaves your variable names as you type them BUT if you type a variable. Sometimes your spacing is changed in expressions.- -- > Run your program - -- . Using the mouse, select the Run option from the menu at the top of the. The program will then ask. Fahrenheit temperature - - type a number in (then press. ENTER). You should see the answer printed by the program. Press. ENTER to get back to the program. Press the ALT key to activate the menu at the top of the screen. At. this point you can press the key corresponding to the highlighted. Press R (for run) then S. Again, enter a temperature when asked. Press function key F5. This starts your program running. Print your program. File option. from the menu (eitherby using. ALT key and then F) and then choose the. The program should be printed on the laser printer in. Save your program - -- . Save. As option. Now you must select the Z drive to save your program. A drive to save the program on. To do this go to the Dirs/Drives box and, using the mouse. Z or the A drive ( [- Z- ] or [- A- ] ). NOTE. To use A you must have a disk with you! Click on the Z or A. OK. You will see that the. Z: \*. BAS (or A: \*. BAS). The name we. DOS filename; that is, the. QBasic will automatically put an extension of BAS onto your. Name this one TEMP; that is, type in the word TEMP. When you have correctly selected the Z or A drive and. OK. - -- > Exiting QBasic - -- . File and then Exit from the menu. You should be back at the. Computer Science menu. Program Often a program. Clearly while working on a. You can also retrieve a program you have saved and modify it (or just. In this part of the lab. Retrieve the TEMP. Start Qbasic back up by selecting Quick. Basic from. the menu, then clear the box to get the blank screen. Choose the file. option from the menu and then choose open. Change the drive to. Z or A drive (whichever drive you saved on) (as before to change. Dir/Drives box and click on. Z or A and then on OK). You should see the file TEMP. BAS in the. files box. Click on it and then, after checking to make sure that. TEMP. BAS appears in the File Name box, click on OK (or press ENTER). The program should appear. Now make the following changes. Replace the comma in. INPUT statement with a semicolon. Run the program. Note that now. INPUT. statement; that is, with a semicolon a question mark is automatically. Change the INPUT statement. INPUT "What is the temperature in degrees Fahrenheit"; Ftemp. Run the program. - -- > Replace the. PRINT statement with commas. Run the program. The. What is different about it? Put the. semicolons back and now change the quotation marks in the print. PRINT "The Celsius. Ctemp; degrees.". Run the program. What. Note the difference in how the print statement treats. Fix things back to the way they. Syntax Errors in. Programs Unfortunately it. To see how QBasic responds when you. Change the keyword. PRINT to PRIMT and run the program. What happens? Now. PRIMT back to PRINT. Remove the quotes. PRINT statement and run the program. What. - -- > Put the quotation. Run the program. What happens? Look closely at the program after you run it - -. QBasic has changed something for you. What did it do?). Leave the * out of. Ctemp. Run the program. What happens? - -- > Put the * back. Ftemp in that statement to Ftimp. Run the program. entering 9. Fahrenheit temperature. The answer you get will be. WRONG (the correct answer is 3. The computer does not know what Ftimp is (you have not stored in. Ftimp and the computer has no way of. Ftemp) so it uses a value of 0 in its calculation. Change Ftimp back to. Ftemp. Now in the INPUT statement change Ftemp to F temp. Run the program. - -- > Fix Ftemp in the. INPUT statement and then change Ctemp in the PRINT statement to C. Run the program. What happens? Why do you think the computer did what it did? Look closely at. the program - - you will see that QBasic has changed your PRINT. It assumed that C and temp were two separate variables you. Finally, fix Ctemp. What happens? What do you. Program Enough of. We can clear out the. FILE. and then NEW. Since we have made changes to the old program without. Choose YES. if you want to save the revised program; otherwise choose NO. You. should then have a blank screen. Write a program. that will ask for three test grades and will then compute and print. This problem is similar to the temperature problem in that we just. We. will need four variables - -- one for each test grade (use the variable. Test. 1, Test. 2, and Test. Average). The program is started on the next page. Finish writing out the program and then type it in. REM Test Average. REM Programmer's Name (put your name here). REM This program computes the average of three tests. INPUT "What did you make on the first test"; Test. INPUT "What did you make on the second test"; Test. Run your program to. First run it and enter grades of 7. The. program should print out 7. Next run it and. enter grades of 8. If you are. getting the wrong answers or syntax errors, carefully study your. Some typical syntax. Some typical mistakes. Test. 1 in one place and Test. One in another). parentheses (or misplaced parentheses) in expressions. Save your program and. Write a program to. The. program should take as input the regular price of the item and the. It should then compute. Make your program general - - that is, use. Type in your program. To test try the following data: Input: Regular price. Discount 2. 5. Your answers should be: Dollar amount of the. Sale price: $3. 0. Tax: $1. 6. 2, Total: $3. Now. run it again with the following data: Input: Regular price 1. Discount 1. 5. Your answers should be: Dollar amount of the discount. Sale Price: $1. 1. Tax: 0. 4. 97. 25, Total: $1. Note: we. don't know how to tell BASIC to round these dollar amounts yet so it. Save the program and get a printout. Always be sure to exit. QBasic and log off when you are through working! Also, to be safe.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2019
Categories |