# Computer Languages

.. did not. adda.f Adds 3 Numbers instead of 2. PROGRAM ADD 3 REAL NUM1, NUM2, NUM3, SUM PRINT *, ‘Enter three numbers: ‘ READ *, NUM1, NUM2, NUM3 SUM = NUM1 + NUM2 + NUM3 PRINT * PRINT *, ‘The sum of ‘, NUM1, ‘, ‘, NUM2, ‘ and ‘, NUM3, ‘is ‘, SUM PRINT * END All I needed to do to modify the program was add a third number to the declaration, to the initial “PRINT” command, to the “READ” command, to the “SUM =” statement, and to the final “PRINT” command. addb.f subtracts two numbers PROGRAM SUBTRACT REAL NUM1, NUM2, SUB PRINT *, ‘Enter two numbers: ‘ READ *, NUM1, NUM2 SUB = NUM1 – NUM2 PRINT * PRINT *, NUM1, ‘ minus ‘, NUM2, ‘ is ‘, SUB PRINT * END All I needed to do to modify this program was to change the SUM variable to SUB, change the addition sign in the “SUB =” statement to a subtract sign, and change the final printout to print the appropriate statement. addc.f Divides two numbers PROGRAM MULTIPLY OR DIVIDE REAL NUM1, NUM2, PROD PRINT *, ‘Enter two numbers: ‘ READ *, NUM1, NUM2 PROD = NUM1 / NUM2 PRINT * PRINT *, NUM1, ‘ / ‘, NUM2, ‘ is ‘, PROD PRINT * END All I needed to do to modify this program was to change the SUM variable to PROD, change the addition sign in the “SUM =” statement to a division symbol, and change the final printout to print the appropriate statement. Conclusion to Section I Writing the hypothesis’s for each the three programs turned out to be more difficult than I would have thought.

Each program had it’s own syntax, and figuring out the syntax was not an easy task. In experiment four, I decided that Fortran was the easiest language to understand, Pascal was the next easiest, and C was extremely difficult to understand. Without looking at the print statements for C, I would not have been able to figure out what the triangle program did at all. Minimizing the syntax and making the commands represent their functions is extremely important for producing a readable, programmable language. Section II: Programming In C++ Introduction to Section II For the last week in class, we have been working exclusively with C++ without using computers, so I have been looking forward to seeing the programs I’ve written in action.

We Will Write a Custom Essay Specifically
For You For Only \$13.90/page!

order now

After programming in assembly language, the prospect of writing programs that will write out lines of characters that actually mean something is thrilling to me. I have heard that programming in C++ is a pain in the butt, but I can not imagine that it is nearly has laborious as programming in assembly language. In the section, I will find out if I can cut it as a C++ programmer. Experiment 5: taxes.cc Hypothesis First the program reads in your taxable income. If your taxable income is less than \$20,000 a year, the program multiplies your taxable income by the low-rate tax (15%), and that value is your tax.

If your taxable income is less than \$50,000 and greater than or equal to \$20,000, the program multiplies your taxable income by the mid-rate tax (28%), and that value is your tax. If your taxable income is greater than or equal to \$50,000, the program multiplies your taxable income by the high-rate tax (.31), and that value is your tax. Finally, the program prints your tax. Because we have been studying C++ for the last week, understanding this program was not very difficult at all. If it were not for that experience, this would probably be one of the more difficult programs to read. The program uses quiet a bit of syntax, and the parentheses, brackets, and symbols make it look cluttered and unorganized.

On the good side, the program has all the constants and variables at the beginning were they can be easily changed. Conclusion The program worked as I thought it would in my hypothesis for all positive numbers. For 0, the program returned zero, and for negative numbers, the program returned the corresponding negative answers. Experiment 6: determine grade.cc The Algorithm Get a value for minimum satisfactory score. Get a value for student’s score.

If student’s score is greater than or equal to minimum satisfactory score then Print the message “Student’s score is satisfactory.” Else (student’s score is less than minimum satisfactory score) Print the message “Student’s score is unsatisfactory.” Stop. The Source Code // Program: Determine Grade // Author: Nathan Lindquist // Date Written: November 3, 1999 // Purpose of Program: To read in a minimum satisfactory score and a // student’s score, and determine if the student’s score is satisfactory // or unsatisfactory, based on the minimum satisfactory score. // #include *iostream.h* int main () { double min satisfact score; double student score; cout ** endl ** “Enter the lowest satisfactory score.” ** endl; cin ** min satisfact score; cout ** endl ** “Enter the student’s score.” ** endl; cin ** student score; if (student score *= min satisfact score) { cout ** endl ** “Student’s score of ” ** student score; cout ** ” is satisfactory.” ** endl ** endl; } else { cout ** endl ** “Student’s score of ” ** student score; cout ** ” is unsatisfactory.” ** endl ** endl; } } Experiment 7: Modifying A C++ Program The Algorithm Get a value for points scored. If the value of points scored is greater than or equal to 90, Print the message “This vegetable is Grade A Fancy.” Else if the value of points scored is greater than or equal to 84, Print the message “This vegetable is Extra Standard.” Else if the value of points scored is greater than or equal to 10, Print the message “This vegetable is Standard.” Else, Print the message “This vegetable is Substandard.” Stop. The Source Code // Name of Program: Determine Veggie Class // Author: Nathan Lindquist // Date written: November 3, 1999 // Purpose of Program: To read in the point value of a U S Department // of Agriculture graded canned vegetable and decide which class (Grade A // Fancy, Extra Standard, Standard, or Substandard) that canned vegetable // fits into.

// #include *iostream.h* int main () { int point score; cout ** endl ** “Enter the USDA point score of a canned vegetable ” ** endl; cout ** “(the score should be an integer.)” ** endl; cin ** point score; if (point score *= 90) { cout ** endl ** “This vegetable is Grade A Fancy” ** endl; } else if (point score *=85) { cout ** endl ** “This vegetable is Extra Standard” ** endl; } else if (point score *=70) { cout ** endl ** “This vegetable is Standard” ** endl; } else { cout ** endl ** “This vegetable is Substandard” ** endl; } } Tests Input Output 105 This veg. is Grade A Fancy 93 This veg. is Grade A Fancy 90 This veg. is grade A Fancy 87 This veg. is Extra Standard 85 This veg. is Extra Standard Input Output 76 This veg.

is Standard 70 This veg. is Standard 65 This veg. is Substandard 0 This veg. is Substandard -13 This veg. is Substandard Experiment 8: Comparing C++ And Assembly Language The Algorithm The values of Integer and Total are 0.

While Integer is not equal to -1 Get a new value for Integer. Set the value of Total equal to the previous value of Total + Integer. Print the value of Total. The Source Code // Name of Program: Add Until // Author: Nathan Lindquist // Date Written: November 3, 1999 // Purpose of program: To read in integers and add them // until an end number (-1) is entered. When the end // number (-1) is entered the program ends.

// #include *iostream.h* int main() { const int EndNumber= -1; // When this integer is entered, the total // is printed, and the program ends. int Integer; int Total; Integer = 0; Total = 0; while (Integer != EndNumber) // This will do the following steps until // the end numver is entered. { Total = Total + Integer; cout ** endl ** “Enter an integer to be added. Enter the integer ” ** endl; cout ** EndNumber ** ” to print the total and end this program.”** endl; // These two cout commands tell the user to “Enter an // integer to be added. Enter the integer [EndNumber] // to print the total and end this program.” cin ** Integer; } cout ** endl ** “The total of all the integers you ” ** endl; cout ** “entered, except for the “; cout ** EndNumber ** “, is ” ** Total ** “.” ** endl ** endl; // These final three cout commands print “The total of // all the integers you entered, except for the // [EndNumber] is [Total].

} Tests Inputs Manual Calculations Output 3, 30, 10, 7, 18, -1 3 + 30 +10 + 7 + 18 = 68 68 -15, -20, -40, -7, -1 -15 + -20 + -40 + -7 = -82 -82 7, 0, 31, -128, -15, 75 -1 7 + 0 + 31 + -26 + -15 = -3 -30 127, -36, 15, -118, 0, 43, 49, 18, -1 126 + -36 + 15 + -118 + 0 + 43 + 49 + 18 =97 98 Conclusion While the above C++ program is actually longer than my assembly language program from last lab, the C++ program above is ten times better. The C++ program actually tells the user what value to enter and what the output means. Whereas as in assembly language, a user would not know what to input or what the output means. In the above program the constant that ends the program can be easily switched from -1 to some other number; in assembly language, switching a constant like that could take an hour. In the above program, changing the program from adding numbers, to multiplying them would be a matter of changing one sign; in assembly language, such a change quadruples plus the size of your program.

Conclusion to Section II Compiling the C++ programs actually worked out fairly well for me. If my program had an error in it when I tried to compile it, the computer would tell me what line the error was on, and it would point to what it thought the error was. Fortunately, I did not end up with any serious problems, most of my mistakes were just typos. I heard that many others where having a very difficult time compiling their C++ programs. Compared to assembly language, programming in C++ is no problem. Conclusion Programming in Fortran, Pascal, and C++ is much more productive then programming in assembly language. A whole array of much more advanced tools is at our disposal.

Now, we can write whole lines of characters, label variables and constants, use Boolean expressions with variables and numbers other than zero, write comments into the program, and the list of new tools goes on, and on. Each one of these tools by itself would take hours, if not days to write an efficient assembly language program for. In high level programming language, we don’t have to worry about registers, memory, storage, retrieval, and other assembly language functions. To write a program that instructs the user what to enter, inputs the side lengths of a triangle, and outputs the kind of triangle it is, would take weeks of boring, meticulous assembly language programming. With Pascal, Fortran, and C++, the same program takes an hour or less.