Introduction To Computing (ECEG-2207) Labratory Manual (Version 2.0)
Introduction To Computing (ECEG-2207) Labratory Manual (Version 2.0)
Objective
• Enable students to be familiar with windows operating system.
• Enable students to be familiar with the basic hardware components of computers.
• Familiarize students with visual studio IDE.
Preparation Tasks
• No preliminary preparation required for this laboratory session
b. Understanding directory structures, file/directory creation and deletion etc in Microsoft Windows environ-
ment.
c. Running and closing application software.
d. Editing of text documents using notepad and Microsoft word.
Objective
• Enabling students to be familiar with different c++ program development IDEs [visual studio, code blocks,
DevC++ . . .)
• Enabling students to Execute simple C++ codes.
• Enabling students to debug programming bugs.
Preparation Tasks
• No preliminary preparation is required for this laboratory session.
Activities
a. Write a simple C++ program that displays a text to the console screen:
Hello!
The name entered by user
Congratulations for being the part of this fantastic course!”
c. Write a C++ program that takes two numbers from the user and computes the sum, difference and product
of the two numbers.
d. Write a simple c++ program that displays the following patterns at the console.
My name is xyz
I am 24 years old
I have a great interest in C++ programming
But, unfortunately, the program has syntax errors and even after syntax errors are corrected it doesn’t
display the expected text as per the requirement. So, identify the syntax errors and debug them. In addition,
it is required to modify the program to display the exact required text.
#include<iostream>
Using namespace std;
Int Main ( )
{
cout<<“my name is xyz”
cout>>“I am 24 years old”;
cout<<“I have a great interest in c++ programming”;
Return 0;
}
Objective
• Enable students to be familiar with the basic operators of C++ programming language such as:
→ Arithmetic operators
→ Relational and logical operators
→ Assignment and compound assignment operators
→ Increment and decrement operators and operator precedence.
Preparation Tasks
• Every student who come to the laboratory is expected to understand the exercises prior to attending the
laboratory class.
• It is also expected to develop algorithm for solving the laboratory exercises. The algorithm shall be developed
either using pseudo code or flowcharts. Each student will submit his/her preparation material at the end of
the laboratory session and it will be part of the laboratory exercise assessment. Those students who fail to
do their preliminary preparation exercise will be prohibited from attending the laboratory session.
Activities
a. Write a simple C++ program that accepts a number from the user and displays the sine, cosine, tangent of
that number.
b. Write a simple C++ program that calculates the area of any triangle using Heron’s area formula.
where
a+b+c
s=
2
and a, b and c are the the sides of the triangle.
→The program is expected to ask the user to enter the measure of the three sides of a triangle and
display the result in a user friendly manner.
→The mechanism of taking input from the user shall be as follows:
Enter the first side of the triangle: The input shall be entered by the user
Enter the second side of the triangle: The input shall be entered by the user
Enter the third side of the triangle: The input shall be entered by the user
→Expected Output
The area of the triangle is: The output calculated by the program
c. Write a simple C++ program that accepts the values of two variables from the user and swaps the content
of the variables. This program shall be implemented in to two ways:
→Using a third variable
→Without using a third variable and for this this case use compound assignment operators)
d. Write a C++ program that calculates the total amount and the earned interest by a bank client for a certain
amount of principal deposited in a bank. After computing the required value display the result at the console.
The program shall be interactive and take the required parameters from the user and should display the
result to the console in a user friendly manner.
The program is expected to take the following parameters from the user in the following manner:
→ Mechanism of taking input from user
Enter the principal: The input shall be entered by the user.
Enter the Annual Rate of interest: The input shall be entered by user.
Enter the time: The input shall be entered by the user.
→ Expected Output
The total amount of the deposit is: The output computed by the program
The net interest of the deposit is: The output computed by the program
Note: the result of the calculation shall have a maximum of two significant digits i.e. it should be like
“the net interest of the deposit is: 1234.97 birr”. To make the display more attractive it is expected to use
the I/O manipulator of C++ programming language.
e. Modify the above program (d) for calculating the principal when other parameters are given.
f. The general characteristics of a semiconductor diode can be defined by the following equation
k×VD
ID = IS × (e TK
− 1)
where k = 11, 600K/V for Silicon, VD is the diode voltage in Volts, TK is the temperature in kelvins, IS is
the saturation current in Amperes and ID is the diode current.
Write a program that accepts IS (ranging from 10−15 A upto 19−9 A), VD (ranging from 0 to 1 Volts) and
TK (ranging from -500 C to 1500 C) from user and calculates ID .
g. Write a program that prints a student information in a table. The information includes the Name of the
student, his/her Department, ID. Number, Age, Stream, preference research interest and current CGPA. The
output shall be presented in a tabular form with the following rules:
The maximum number of significant digit shall be 2, the width of each column shall be 20 characters, and the
unoccupied columns of the table shall be filled with “-” and the columns shall be left justified.
Objective
• Enabling students to use C++ control statements for applying in real world programing endeavors.
→ Enabling students to effectively use the “while”, “do. . .while”, and “for loops” for writing C++
programs that solve real world problems.
→ Enabling students to use use the conditional statements(“if ” and nested “if. . .else” statements)
and “switch” statements to control program flow control and solve real world programming problems.
Preparation Tasks
• Every student who come to the lab is expected to understand the exercises prior to attending the lab.
• It is also expected to develop algorithm for solving the laboratory exercises. The algorithm shall be developed
either using pseudo code or flowcharts. Each student will submit his/her preparation material at the end of
the laboratory session and it will be part of the laboratory exercise assessment. Those students who fail to
do their preliminary preparation exercise will be prohibited from attending the laboratory session.
Activities
a. Write a C++ program that implements a console based calculator. The program shall prompt the user what
kind of calculation he/she wants to perform and prints the result to the computer screen. The program must
be implemented using switch statements and is expected to have the following functionalities:
→ Addition of two numbers:
→ Subtraction of two numbers:
→ Multiplication of two numbers:
→ Division of two numbers:
→ Display the trigonometric values of a number entered by user. For this case, the program is expected
to display the sine, cosine, tangent, secant, cosecant and cotangent of a number entered by user.
→ The common logarithm and the natural logarithm of a number.
#include<iostream>
using namespace std;
int main()
{
int size;
cout<<“enter the size”<<endl;
cin>>size;
int c=0;
for(int i=1; i<=size; i++)
{
while(true)
{
cout<<“*”;
c++;
if(c>=(size+1)-i)
{
break;
}
c=0;
cout<<“endl”;
}
} //end of for loop
return 0;
}
d. Using loop write a program that displays the following patterns. The size of the patterns shall be determined
by the user.
e. Write a C++ program that sums the first n prime numbers. The number n shall be determined by the user.
The program execution should be as follows:
What numbers of prime numbers you want to add: n will be entered by the user.
The sum of the first n prime numbers is: The output will be displayed by the program.
f. Write a program that computes the product of the first 1000 numbers which are multiple of 7 using while
loop only.
g. Write a C++ that implements a number guessing game based on the following rules:
→ Rule 1: The game has three guessing levels based on the first trial
Level 1: if the player guesses 5 of the number
Level 2: if the player guesses 15 of the number
Level 3: if the player guesses 25 of the number
→ Rule 2: The guessing chances will be as follows
Level 1: guess has 9 more chances to repeat
Level 2: guess has 6 more chances to repeat
Level 3: guess has 3 chances to repeat and all the chances of repletions are allocated based on the first
trial
→Rule 3: If the player finds the number it shall prompt a message congratulations you get the number
the number is: the assigned number
→Rule 4: if the number is not found, the program shall give a hint of the interval in which the number
is found. The interval shall be [assigned number-100, assigned number+100] and the hints will be useful for
repeating the above steps for one more time only.
→Rule 5: The program shall have a score report feature based on the following rules.
If a person gets at its first trial its score will be 100
If the player guesses at level one in each trial 2 points will be deducted from 100
If the player guesses at level two in each trial 4
points will be deducted from 100
If the player guesses at level one in each trial 8 points will be deducted from 100
Objective
• Using basic data structures(Arrays and Strings) of C++ in real world programming endeavors.
→Students will be equipped with the appropriate knowledges of C++ data structures like arrays and
strings to apply them in any real world programming endeavor.
→ Students will be able to use single and multi-dimensional arrays when they are engaged in programming
endeavors.
Preparation Tasks
• Every student who come to the lab is expected to understand the exercises prior to attending the lab.
• It is also expected to develop an algorithm for solving the laboratory exercises. The algorithm shall be
developed either using pseudo code or flowcharts. Each student will submit his/her preparation material at
the end of the laboratory session and it will be part of the laboratory exercise assessment. Those students
who fail to do their preliminary preparation exercise will be prohibited from attending the laboratory session.
Activities
a. Write a C++ program that converts binary numbers in to the equivalent decimal numbers. The binary
numbers shall be taken as single dimensional array from the user.
b. Write a C++ program that accepts a two 3X3 matrices and compute the following:
→ Add the entire elements of the matrix and display to the console.
→ Store the sum of each rows of the first matrix in a single dimensional array.
→ Transposes the two matrices.
→ Computes the sum of the two matrices.
→ Multiply the two matrices.
→ Exchanges the diagonal of one of the matrices.
c. Write a C++ program that that takes your name from the keyboard and displays the following:
If your name has more than 10 characters, “your name is too long!”
If it comprises between 5 and 9 characters, “Your name is medium!”
If it comprises less than five characters, “your name is to short!”
d. Write a C++ program that take to strings from keyboard and concatenate the two strings and store in the
third string.
e. Write a C++ code that searches the term apply and country from the following text.
We offer a wide range of courses at all levels. If you are applying through one of our representatives in
your country, they will guide you through making your application.
f. Write a C++ program that takes two strings from the keyboard and sorts them.
g. Write a C++ program that take two integers from the keyboard, compute their sum and convert back the
result to string and concatenate the result with other string variable and print it at the console.
Objective
• Enabling students to create custom data types using structures and enumerated data types: This laboratory
session focuses on:
→Mastering the concepts of structures and enumerated data types through practical programing exer-
cises.
→Familiarize custom data types like enumeration, structures
→Instantiating structures and accessing each element of the record in the main function
Defining structures within structures
→Creating arrays of structures
Preparation Tasks
• Every student who come to the lab is expected to understand the exercises prior to attending the lab.
• It is also expected to develop the high level structures diagram of the structures defined in c.
Activities
a. Define a structures called “Employee Record” that records the information of typical employee in given
company. The defined structures is expected to record the following employee data:
Employees first name, middle name, last name, employees ID, Gender, Employees address (city, street,
phone (mobile, fixed line for home and office, Fax, email, P.O.Box), department of work, salary, hire day and
quit (date, month, year)
Note:
1. Each record element shall be assigned with the appropriate data type
2. The constructed structures shall be instantiated at the main function and the sample data type
shall be feed to the record.
3. The records of the structure shall be displayed to the console with the appropriate formatting.
b. Define array of type Employee Record with the size of 10 elements to store the records of the employees.
c. Optimize the above definition by grouping the related data types within sub structures. Within the Em-
ployee Record define the following structures and repeat the steps of a from 1-3.
→ Employee name rec which records the first name, middle name and last name of employee Em-
ployee adress rec which records the city, street, mailing tyepe rec The mailing type rec is a structures
which records mobile, fixed line for home and office, Fax, email, P.O.Box of employee Company specific rec
which records the salary, department of work, hire date rec, and quit date rec Hire date rec and quit date
rec are structures that record the respective hire and quit day, month, and year of employee
→Finally define structures called Employee Record which records Employee name rec, Employee address rec,
Company specific rec, Hire date rec and quit date rec .
Objective
• Understanding the basic of C++ functions through practical programming exercises. This session focuses on:
→ Code modularization using functions
→ Functions prototypes
→ Overloaded functions
→recursive functions
Preparation Tasks
• Every student who come to the lab is expected to understand the exercises prior to attending the lab.
• It is also expected to develop an algorithm for solving the laboratory exercises. The algorithm shall be
developed either using pseudo code or flowcharts. Each student will submit his/her preparation material at
the end of the laboratory session and it will be part of the laboratory exercise assessment. Those students
who fail to do their preliminary preparation exercise will be prohibited from attending the laboratory session.
Activities
a. Write a function that accepts an array of non-negative integers and returns the second largest integer in the
array. Return -1 if there is no second largest integer.
b. Write a function that takes an array of integers as an argument and returns a value based on the sums of
even and odd numbers in the array. Let x = the sum of the odd numbers in the array and let y =
the sum of the even numbers in the array. The function should return x − y.
c. Write a simple recursive functions that computes the factorial of a certain number n and Fibonacci series
from the beginning up to n. The value of n shall be determined by the user.
d. Write a C++ function named prev nxt that takes a number from the user and stores the predecessor and
successor of that number in two previously defined variables. Those variables which are nominated for storing
the predecessor and successor of the number shall be declared and initialized prior to the function call. The
content of these variables shall be completely modified after the prev nxt function call.
e. Write a C++ program that is supposed to perform addition of two integers, addition of two long integers,
addition of two double precision floating numerals and concatenation of two strings (For this case you shall use
the <string>library). All the above functionalities shall have their own C++ functions and all the functions
shall be named ovr f un.
f. Write a single C++ function called getMax which returns the bigger number among two integers, two dou-
ble precision floating numerals and two single precision floating numerals. The function also expected to
return a string or character which come at higher position when the two characters and strings are sorted
alphabetically. The functions is required to return negative 1 (-1) if the two parameters are equal.
(Note: For the case of numerals, the function returns the bigger number among the two if it exists but for
character and strings the function is expected to return the one that come at higher level when they are
sorted in alphabetical order)
g. Write a C++ function that computes the sum of the first 1000 positive integer numerals recursively.
h. Assume that you are working in a large software company and participate in a certain software development
project. The software, which is under development, has several modules and the modules are further divided
into several sub modules. As a student and novice programmer, you are requested to develop the password
checker sub-module of the software based on a certain set of predefined rules. A password is valid if and only
if the following criteria are fulfilled:
→ The password shall comprises combination of letters, numbers and special characters.
→ The length of the password shall be at least 15 characters.
→ The password shall have palindrome characteristics.
(A palindrome is a string that reads the same forwards as backwards. The following are palindrome
strings: 145787541, MADAM, RACECAR, ABABA, 1221)
The program shall be well organized and modularized through extensive use of C++ functions as much
as the program complexity requires.
Objective
• Understand the basic concepts of pointers through practical programming exercise.
• Understand dynamic memory allocation Memory management concepts.
• Using C++ file input output library(File I/O) to perform basic manipulation of files.
Preparation Tasks
• Every student who come to the lab is expected to understand the exercises prior to attending the lab.
• It is also expected to develop an algorithm for solving the laboratory exercises. The algorithm shall be
developed either using pseudo code or flowcharts. Each student will submit his/her preparation material at
the end of the laboratory session and it will be part of the laboratory exercise assessment. Those students
who fail to do their preliminary preparation exercise will be prohibited from attending the laboratory session.
Activities
a. Write a C++ program that sorts an array. The size of the array shall be determined by the user at run time
(the size of the array shall be determined dynamically). The array elements either may be taken from the
user or may be generated using C++ pseudo random number generator.
b. Write a C++ program that performs the following matrix operations. Add two matrices, multiply two
matrices and transpose a matrix.
→The program shall be user friendly and has a feature of correcting errors. For instance if a user tries to
multiply two matrices of which the size of the row of one of the matrix is not the same as size of the column
of another matrix shall throw exception and the exception shall be caught properly.
→The size of the matrices shall be determined by the user.
→ All the operation shall be organized using functions. For all of the above operations, use of dynamic
memory allocation concept is mandatory.
→ All dynamically allocated memories shall be freed after the use (use of memory management concept
is a must)
c. Write C++ program that write the following text to a file called “myInfo.txt” at your preference directory
in your computer.
|————————————–|
| My personal info: |
|————————————–|
|Name: your name |
| ID. NO.: your ID. NO. |
| Hobby: list of your hobbies |
| Additional info: any additional info. |
|————————————–|
d. Update the existing text file you write in c to include your phone number, your country and your favorite
book. You shall use I/O manipulators to format your text.
e. Write a C++ program which reads the text file that you write in c and d and displays it at the console.
f. Save the output of the programs that you did c and d in a text file in your computer at your preferred
directory.
Objective
• Introduce the basic Object-Oriented Programming concepts.
• Understand the basic concepts of classes and objects in c++ programming language context.
Preparation Tasks
• Every student who come to the lab is expected to understand the exercises prior to attending the lab.
• It is also expected to develop an algorithm for solving the laboratory exercises. The algorithm shall be
developed either using pseudo code or flowcharts. Each student will submit his/her preparation material at
the end of the laboratory session and it will be part of the laboratory exercise assessment. Those students
who fail to do their preliminary preparation exercise will be prohibited from attending the laboratory session.
Activities
a. Define a class called RectangleCalculator. The class shall have:
→Two private fields: length and width
→ Functions that access the private fields of the class: setLength, setWidth, getLength, getWidth
→ Constructors that initialize the fields of the class. The class shall have both parameterized and
parameterless constructors.
→ Destructors that releases the memory from the constructed object when it becomes no serviceable
to the program.
→ Functions that calculate the area and perimeter of a rectangle
→ After defining the class it is expected to instantiate the class in the main functions and by feeding
the required data test the required output.
b. Modify the above program by making all the constructors, destructors and functions implementation outside
the class definition. (Hint: define the function prototypes in the class and use scope resolution operator and
implement the functions outside the class definition.
c. (Optional) Define a class called parallelogramCalculator that inherits the class RectangleCalculator. The
class shall have:
→ One private field: angle
→ Functions that access the private field of the class: setAngle, getAngle
→ Constractor that initialize the fields of the class
→Functions that calculate the area of parallelogram
Note: Since this class inherits the RectangleCalculator class, it is not expected to define functions and fields
which are already defined in its parent class. So, we are required to reuse the parent class members in this
class rather than recreating them.
I HOPE WE HAVE SPENT GOOD TIME THROUGHOUT THE SEMESTER AND I WISH
ALL GOOD THINGS TO BE WITH YOU IN ALL ASPECTS OF YOUR FUTURE LIFE!
Good Luck!!!