Lab Work #1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Libyan Academy-Engineering School

IT department

Advanced Programming ITE610

Lab Work #1

Activity A

Review Questions (read chapter 1 of Gaddis’s book)

1. A(n) __________ is a set of instructions that a computer follows to perform a task.

a. compiler b. program c. interpreter d. programming language

2. The physical devices that a computer is made of are referred to as __________.

a. hardware b. software c. the operating system d. tools

3. The part of a computer that runs programs is called __________.

a. RAM b. secondary storage c. main memory d. the CPU

4. Today, CPUs are small chips known as __________.

a. ENIACs b. microprocessors c. memory chips d. operating systems

5. The computer stores a program while the program is running, as well as the data that the program is
working with, in __________.

a. secondary storage b. the CPU c. main memory d. the microprocessor

6. This is a volatile type of memory that is used only for temporary storage while a program is running.

a. RAM b. secondary storage c. the disk drive d. the USB drive

7. A type of memory that can hold data for long periods of time, even when there is no power to the
computer, is called __________.

a. RAM b. main memory c. secondary storage d. CPU storage

8. A component that collects data from people or other devices and sends it to the computer is called
__________.

a. an output device b. an input device c. a secondary storage device d. main memory

9. A video display is a(n) __________ device.

a. output device b. input device c. secondary storage device d. main memory

10. A __________ is enough memory to store a letter of the alphabet or a small number.

a. byte b. bit c. switch d. transistor

11. A byte is made up of eight __________.


a. CPUs b. instructions c. variables d. bits

12. In the __________ numbering system, all numeric values are written as sequences of 0s and 1s.

a. hexadecimal b. binary c. octal d. decimal

13. A bit that is turned off represents the following value: __________.

a. 1 b. –1 c. 0 d. “no”

14. A set of 128 numeric codes that represent the English letters, various punctuation marks, and other
characters is __________.

a. binary numbering b. ASCII c. Unicode d. ENIAC

15. An extensive encoding scheme that can represent characters for many languages in the world is
__________.

a. binary numbering b. ASCII c. Unicode d. ENIAC

16. Negative numbers are encoded using the __________ technique.

a. two’s complement b. floating point c. ASCII d. Unicode

17. Real numbers are encoded using the __________ technique.

a. two’s complement b. floating point c. ASCII d. Unicode

18. The tiny dots of color that digital images are composed of are called __________.

a. bits b. bytes c. color d. pixels

19. If you were to look at a machine language program, you would see __________.

a. Python code b. a stream of binary numbers c. English words d. circuits

20. In the __________ part of the fetch-decode-execute cycle, the CPU determines which operation it
should perform.

a. fetch b. decode c. execute d. immediately after the instruction is executed

21. Computers can only execute programs that are written in __________.

a. Java b. assembly language c. machine language d. Python

22. The __________ translates an assembly language program to a machine language program.

a. assembler b. compiler c. translator d. interpreter

23. The words that make up a high-level programming language are called __________.

a. binary instructions b. mnemonics c. commands d. key words

24. The rules that must be followed when writing a program are called __________.

a. syntax b. punctuation c. key words d. operators


25. A(n) __________ program translates a high-level language program into a separate machine
language program.

a. assembler b. compiler c. translator d. utility

True or False Questions

1. ( )Today, CPUs are huge devices made of electrical and mechanical components such as vacuum
tubes and switches.

2. ( )Main memory is also known as RAM.

3. ( )Any piece of data that is stored in a computer’s memory must be stored as a binary number.

4. ( )Images, like the ones you make with your digital camera, cannot be stored as binary numbers.

5. ( )Machine language is the only language that a CPU understands.

6. ( )Assembly language is considered a high-level language.

7. ( ) An interpreter is a program that both translates and executes the instructions in a highlevel
language program.

8. ( )A syntax error does not prevent a program from being compiled and executed.

9. ( )Windows Vista, Linux, UNIX, and Mac OSX are all examples of application software.

10. ( ) Word processing programs, spreadsheet programs, email programs, web browsers, and games
are all examples of utility programs.

Give Short Answers for the following:

1. Why is the CPU the most important component in a computer?


2. What number does a bit that is turned on represent? What number does a bit that is turned off
represent?
3. What would you call a device that works with binary data?
4. What are the words that make up a high-level programming language called?
5. What are the short words that are used in assembly language called?
6. What is the difference between a compiler and an interpreter?
7. What type of software controls the internal operations of the computer’s hardware?
8. Use what you’ve learned about the binary numbering system in this chapter to convert the
following decimal numbers to binary: 1110 6510 100 10 25510 410.
9. Use what you’ve learned about the binary numbering system in this chapter to convert the
following binary numbers to decimal: 11012 10002 1010112
10. Look at the ASCII chart in Appendix C of text book (Gaddis) and determine the codes for each
letter of your first name. (Ahmed Abdullah).
Activity B Lab Exercises (30 points for C++ + 30 points for Python)

Note: every programming is presented by the student in the lab.

Download C++ compiler, use Borland C-free compiler or any Borland C++ compiler that is
compatible with your machine(PC). You may download eclipse or NetBeans (IDE).

1. Write functions for the following


a. Edit and run the following code to test your compiler.

//Swapping of two numbers using function call by reference


//Author Ahmed
//date 3/21/2022
//program to illustrate the use of function
// to swap 2 numbers in memory
#include<iostream.h>
#include<conio.h>
void swap (int &, int &); //function prototype
// main starts here …
int main()
{
//clrscr();
int num1,num2;

cin>>num1>>num2;
cout<<"”\nBefore swapping:\nNum1: "<<num1;
cout<<endl<<"num2: "<<num2;
swap(num1,num2); //function call
cout<<"”\n\nAfter swapping : \Num1: "<<num1;
cout<<endl<<"num2: "<<num2;
getch();
return 0 ;
}
//function fefinition swap()
void swap (int & a, int & b)
{
int temp=a;
a=b;
b=temp;
}
b. Add two more functions to your first program that you edited and tested:
First function to add the two number and second function to the determine the largest
number among the two.
c. Write and execute a function to compute Fibonacci series for n (say 50) terms. Fibonacci
series new number is always the sum of the two previous numbers 0+1  1, 1+1  2.

0, 1,1,2,3,5,8, 13, 21, …..


d. Repeat the function for Fibonacci series by calling the function recursively.
e. Write a program that gets the length and width of a rectangle, then it computes the
area and prints out the result. Use the following algorithm as a procedural programming
paradigm:

Get length

Get width

Compute area: area = length x width

Display area

f. Repeat the rectangle program by defining rectangle as class in c++ using OOP paradigm.

==================================================================================

2. Download Python 3.10.2 on your machine, then try the following lab exercises
a. Use the Internet to research the history of the Python programming language, and answer
the following questions:
b. Who was the creator of Python?
c. When was Python created.
d. In the Python programming community, the person who created Python is commonly
referred to as the “BDFL.” What does this mean?

e. To make sure that you can interact with the Python interpreter, try the following steps on
your computer. Now, Start the Python interpreter in interactive mode.
f. Use the IDLE shell to test numeric and string operations.

>>> 21 + 450

>>> 23//2

>>>23/2

>>> 5 **3

>>> (5-2)*3/2

>>> “ Assalamu Alaikom:” + “Ahmed”

g. At the >>> prompt type the following statement and then press Enter:

print('This is a test of the Python interpreter.') enter

If you see an error message, enter the statement again and make sure you type it exactly as
it should be.
h. Exit the Python interpreter. (In Windows, press Ctrl-Z followed by Enter. On other systems
press Ctrl-D.) 2. To make sure that you can interact with IDLE, try the following steps on your
computer:

Start IDLE. GUI To do this in Windows, click the Start button, then All Programs. In the Python
program group click IDLE (Python GUI).

i. Type the following program by creating a new file (name it: PyProgram1) and run it.

#Author: Ahmed
# date: 3/14/2022
# Description: program to compute the average of 3 scores...
#!/usr/bin/env python3
print("Hello out there!")

# get input read your name

name = input("Who are you?")

print("Goodbye, " , name)

j. Type the following program save it as PyProgram2 and run it to see the results

#Author: Ahmed
# date: 3/14/2022
# Description: program to compute the average of 3 scores...
#!/usr/bin/env python3
# display a welcome message
print("The Test Scores program")
print()
print("Enter 3 test scores")
print("======================")
# get scores from the user
total_score = 0 # initialize the variable for accumulating scores
total_score += int(input("Enter test score: "))
total_score += int(input("Enter test score: "))
total_score += int(input("Enter test score: "))
# calculate average score
average_score = round(total_score / 3)
# format and display the result
print("======================")
print("Total Score: ", total_score,
"\nAverage Score:", average_score)
print()
print("Bye")
k. Exit IDLE by clicking File, then Exit (or pressing Ctrl-Q on the keyboard.

You might also like