COMPUTER PROGRAMMING (ECE431) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. TUTORIAL 1 Explain the distinction between high levels and low levels programming languages. Why there are so many high-level programming languages available today? Name a few advantages of programming in C++ language. Sketch the architecture of a computer system. Give a brief description and function of each block. What are the standard input and output devices? What are they used for? Sketch the structure of the memory showing the address and data sections. What are a compiler, linker and loader? What is the purpose of header files? Show the two ways comments can be placed in a program. What is an identifier? Why identifiers name and NAME different? What is a variable? Why is C++ is called strongly typed language? Define the variables c, thisVariable, q76354 and number to be of type integer. What is numeric overflow? How is integer overflow different from floating-point overflow? What are the four common types of variables in C++? What are the differences between local variables and global variables? What are the common arithmetic and logic operators in C++? Show two ways how a constant can be declared. Write the conditional expression for the following conditions: a) Variable integer x is tested for greater than or equal to 50 b) Variable integer quik is tested for greater than 70 but less than 150 Write the statement to read an integer from the keyboard and store the value in integer variable a. Write the statement to accomplish the task if the variable number is not equal to 7, print “Number is not equal to 7”. What are compile-time and run-time errors? Give two examples of each type. Programming Exercises 1. 2. 3. 4. Write a program that prints ‘Welcome to C++ programming’. Write a program that prints:‘*************************************’ ‘Faculty of Electrical Engineering’ ‘**************************************’. Write a program to display the following pattern onto the screen. * * * * * * * * * Given the integer variables a=2, b=5, c=7 and floating point variables x=10.0, y=10.5, z=20.0. Use type cast to obtain accurate answers for each of the following expressions: a) c+by-a b) y+a/b c) a+b(z/a) d) x+(b/a)c Sept 2014 / Mohd Uzir 4. 5. 6. 7. 8. Hint: Since a, b and c are integers, the divide operations will give an integer result (truncation). Thus casting will make the result into float without have to change the integers as float. e.g. y+(float)a/b will make the result a/b as float. Careful! Not y+(float)(a/b) Write a program that reads voltage and resistance values, then print out the resulting current using Ohm’s law. Hint: Use the formula I=V/R Write a program that convert the number read as degrees to radians using 1 radian = 57.295779 degrees, correct to three decimal places. Write a program that convert the number (float) read as degrees Fahrenheit (F) into Celsius (C) using C = (100/180)(F-32). Hint: When using the formula, don’t forget to cast division of integers. The easiest way to solve for two simultaneous equations is to use Cramer’s Rule. Use Cramer’s Rule to solve the following equations: 2x – 5y = 9 6x + 10y = 18 Write a program that reads positive integer m and n and then prints mn . Hint: Use the cmath function, pow(m,n) or can also use e(n log m) Part A: Fill the empty spaces with the correct answer. 1. Every C++ program begins execution at the function called _______________. 2. The _______ begins the body of every function and the _______ ends the body of every function. 3. A function name must be followed by ________. 4. A function body is delimited by ________. 5. Every statement ends with a(n) _____________. 6. The ___________ standard function displays information on the screen (monitor). 7. The ___________ standard function is used to obtain data from the keyboard. 8. The expression 11/3 evaluates to ________ and 11%3 evaluates to ________. 9. The actual code for library functions is contained in a ________ file. Part B: Circle the correct answer. 1. All variables must be defined before they are used. TRUE / FALSE 2. It’s perfectly all right to use variables of different data types in the same arithmetic expression. TRUE / FALSE 3. Variables Value and value is considered the same in C++. TRUE / FALSE 4. The divide operator (/) always gives the result of type float. TRUE / FALSE 5. The source file must have the extension .exe TRUE / FALSE 6. The = = symbol means ‘equal’. TRUE / FALSE Sept 2014 / Mohd Uzir
© Copyright 2026 Paperzz