Смекни!
smekni.com

Computer Languages Essay Research Paper Despite having (стр. 2 из 2)

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.