Sei sulla pagina 1di 51

COMPUTER LABORATORY MANUAL

Fundamentals of Programming
(CPS-110)
Fall Semester

DEPARTMENT OF COMPUTER SOFTWARE ENGINEERING


Military College of Signals
National University of Sciences and Technology
www.mcs.nust.edu.pk

1 CPS 110 Fundamentals of Programming


PREFACE
This Lab Manual has been specially designed with the idea of improving and enhancing the problem solving
skills of students through consistent practice and creativity. There are 15 lab activities in this Lab Manual,
which cover all the topics taught in the BS Software Engineering core course CPS-110-Fundamentals of
Programming. Each lab activity has been divided into three parts; Learning Objectives, Practice Questions and
POST-Lab Tasks. Learning Objectives indicate the specific areas of C++ Language programming, in which a
student will become proficient after successfully completing the lab activity. There are about 5 to 6 Practice
Questions of increasing difficulty level, in each lab. These questions have been carefully devised with the idea
of keeping the students interested as well as motivated to complete the designated tasks. A mix of interesting
arithmetic calculations, real life problems and puzzle-like questions has been included in this section. There are
about 2 to 3 POST-Lab Tasks included in each lab activity. These tasks are intended to refine a students
advanced level programming skills. After the completion of a lab activity, students will take the POST-Lab tasks
home, complete these tasks and submit the source code files to course instructor.

PREPARED BY
This Lab manual has been prepared by Lec. Adeela Waqar under the supervision of Dr. Naveed Iqbal Rao, Head
of Computer Software Engineering Department, in the year 2013.

GENERAL INSTRUCTIONS
a. Students are required to maintain the lab manual with them till the end of the semester.
b. All readings/answers to questions/illustrations must be solved in the space provided. If more space is
required then additional sheets may be attached.
c. It is the responsibility of the student to have the manual graded before deadlines as given by the instructor.
d. Loss of manual will result in resubmission of the complete manual.
e. Students are required to go through the experiment before coming to the lab session. Lab session details will
be given in training schedule.
f. Students must bring the manual in each lab.
g. Keep the manual neat, clean and presentable.
h. Plagiarism is strictly forbidden. No credit will be given if a lab session is plagiarised and no resubmission
will be entertained.
i. Marks will be deducted for late submission.

VERSION HISTORY
Date Updated By Details
August 2013 Lec Adeela Waqar First Version Created

2 CPS 110 Fundamentals of Programming


Mapping of CLOs to Lab Experiments

List of Experiments CLO


1 C++ BUILDING BLOCKS-I 1

2 C++ BUILDING BLOCKS-II 1

3 C++ CONTROL STRUCTURES-I 2

4 C++ CONTROL STRUCTURES-II 2

5 C++ CONTROL STRUCTURES-III 2

6 C++ LANGUAGE AND FUNCTIONS-I 3

7 C++ LANGUAGE AND FUNCTIONS-II 3

8 C++ LANGUAGE AND FUNCTIONS-III 3

9 1-DIMENSIONAL ARRAYS-I 3

10 1-DIMENSIONAL ARRAYS-II 3

11 2-DIMENSIONAL ARRAYS-I 3

12 2-DIMENSIONAL ARRAYS-II 3

13 POINTERS & STRINGS-I 3

14 POINTERS & STRINGS-II 3

STRUCTURES 3

3 CPS 110 Fundamentals of Programming


MARKS

Exp Date Experiment Title Max. Marks Instructor


# Conducted Marks Obtained Sign

Grand Total

4 CPS 110 Fundamentals of Programming


LIST OF EXPERIMENTS

EXPERIMENT 1 C++ BUILDING BLOCKS-I 5


EXPERIMENT 2 C++ BUILDING BLOCKS-II 8
EXPERIMENT 3 C++ CONTROL STRUCTURES-I 11
EXPERIMENT 4 C++ CONTROL STRUCTURES-II 15
EXPERIMENT 5 C++ CONTROL STRUCTURES-III 18
EXPERIMENT 6 C++ LANGUAGE AND FUNCTIONS-I 21
EXPERIMENT 7 C++ LANGUAGE AND FUNCTIONS-II 24
EXPERIMENT 8 C++ LANGUAGE AND FUNCTIONS-III 27
EXPERIMENT 9 1-DIMENSIONAL ARRAYS-I 29
EXPERIMENT 10 1-DIMENSIONAL ARRAYS-II 31
EXPERIMENT 11 2-DIMENSIONAL ARRAYS-I 34
EXPERIMENT 12 2-DIMENSIONAL ARRAYS-II 36
EXPERIMENT 13 POINTERS & STRINGS-I 39
EXPERIMENT 14 POINTERS & STRINGS-II 41
EXPERIMENT 15 STRUCTURES43
SEMESTER PROJECT 45
APPENDIX ASCII TABLE 47

5 CPS 110 Fundamentals of Programming


EXPERIMENT 1 C++ BUILDING BLOCKS-I

Learning Objectives
In todays lab, you will practice;
1. Indenting your code.
2. Writing comments in your code.
3. Declaring variables (int, float and char).
4. Using two of the C++ languages most commonly used built-in functions namely cin and cout
with/without using variables.
5. Using basic arithmetic operators available in C++ ( +, - ,* , / ).
6. Using escape sequences in cout statements.

Practice Questions
You can practice the following problems in this lab.
Task 1.1 Declaring Variables
Write a C++ program, which declares integer a, float b and character c. Ask user for an integer value
and store it in a, for a float value and store it in b and for a character value and store it in c. At the end,
print the values of these three variables on screen. Your output should be as below. Indent your code and
include comments for improving the readability of your code.
Enter Integer Value: 448
Enter Float Value: 32.65
Enter Character Value: A
***** You have entered the following values *****
Integer Value is: 448
Float Value is: 32.65
Character Value is: A

Task 1.2 Arithmetic Operations on Variables +, -, *, / , %


Write a C++ program which takes two int values from user and computes their sum, difference, product,
quotient and remainder. At the end, print these results on screen with a beep. Your output should be as
below. Indent your code and include comments for improving the readability of your code.

Enter Value 1: 50
Enter Value 2: 50
Sum : 50 + 50 = 100
Difference : 50 50 = 0
Product : 50 * 50 = 2500
Quotient : 50 / 50 = 1
Remainder : 50 % 50 = 0

6 CPS 110 Fundamentals of Programming C++ Building Blocks I


Task 1.3 Cout Statement with Escape Sequences
By using different escape sequences, write a C++ program, which displays the following output. After every
line, your program must generate a beep. If you already do not know the escape sequence for generating a
beep, find it out for yourself. Indent your code and include comments for improving the readability of your
code.

MCS
MCS
MCS
MCS

Task 1.4 Cout Statement with Escape Sequences


Write a C++ program, which generates the following output. After displaying the output, 5 beeps must be
generated. Indent your code and include comments for improving the readability of your code.

This is a test.
He asked, How are you doing?
Education is the most powerful weapon which
you can use to CHANGE the world.
S

POST-Lab Task # 1.1


(Scientific Calculator in C++)
Total Marks : 10
cmath is a C++ header file which defines different mathematical functions like sin, cos, tan, square root,
exponent and many others. Explore this file using internet resources and make a list of all major
mathematical functions that it contains. Using your findings, write a C++ program which can perform
different mathematical operations on float variables. You must take the values of required variables from the
user. Your program must be capable of computing the following operations; sin, cos, tan, natural
logarithm, common logarithm, exponential, raised to power, square root, ceiling and floor.

Ideally, the values entered by user should not be changed while your program is executing, otherwise your
programs calculations will be based on modified values and thus, will be considered incorrect. Is there any
way to ensure that your program does not accidently modify the values entered by user? If yes, please write
appropriate C++ code to incorporate this feature. If no, explain why it is not possible. Do you think the C++
reserved word const can be useful here?
Output of your program must be presentable and self-explanatory. You may use different escape sequences
to customize output of your program.

7 CPS 110 Fundamentals of Programming C++ Building Blocks I


Web Resources

http://www.cprogramming.com/
http://www.mycplus.com/featured-articles/top-10-applications-written-in-c-cplusplus/
http://www.cplusplus.com/doc/tutorial/program_structure/
http://www.cplusplus.com/doc/tutorial/variables/
http://www.cplusplus.com/doc/tutorial/constants/
http://www.cs.wustl.edu/~schmidt/C++/

8 CPS 110 Fundamentals of Programming C++ Building Blocks I


EXPERIMENT 2 C++ BUILDING BLOCKS-II

Learning Objectives
In todays lab, you will practice;
1. Taking a single character input from user using different built-in functions.
2. Displaying the ASCII values of different characters.
3. Evaluating arithmetic expressions using rules of precedence.
4. Using increment and decrement operators.

Practice Questions
You can practice the following problems in this lab.
Task 2.1 ASCII Values in C++
Imp Note: Find out the differences between get(), getch(), getche() and getchar() before lab session.
Every character has an ASCII value. Write a C++ program, which takes a character input from user and
prints its ASCII value on screen. Your must use all built-in functions for taking character input from user
(like get(), getch() , getche(), getchar() etc), one by one. ASCII Table is included in Appendix A for your
reference. Indent your code and include comments for improving the readability of your code. Your program
should have the following interface.

Enter a Character and I will tell you its ASCII value : B


ASCII value is : 66

Solution :

#include <iostream>
using namespace std;
int main ()
{

char f;
cout<<"Enter a character and i will tell you its ascii value: ";
cin>>f;

cout<<"ASCII value is: "<< int (f);

return 0;
}

9 CPS 110 Fundamentals of Programming C++ Building Blocks II


Task 2.2 Arithmetic Operations and Rules of Precedence
Write a C++ program which prompts the user to enter a float value of temperature in Centigrade, converts it
into Fahrenheit and displays the result on screen. Formula for conversion is C = (F - 32) / 1.8. You must
declare minimum number of variables. Do you think you can avoid using parentheses? Indent your code and
include comments for improving the readability of your code. Your program should have the following
interface.

Enter the temperature in Centigrade: 37


37 Degrees Centigrade is equal to 98.6 Fahrenheit.

Solution :

#include <iostream>
using namespace std;
int main ()
{
float x,y;
cout<<"enter the temperature in centigrade: ";
cin>>x;

y=(x*1.8)+32;
cout<<x<<" degrees is equal to "<<y<<"fahrenheit. ";

return 0;
}

Task 2.3 Arithmetic Operators


Write a C++ program which reads in a three digit number from user and separates its digits. The output of
your program should be as below. Indent your code and include comments for improving the readability of
your code.
Enter a three digit number : 547
There are 5 Hundreds, 4 Tens and 7 Ones in 547.

10 CPS 110 Fundamentals of Programming C++ Building Blocks II


Solution:

#include <iostream>
using namespace std;
int main ()
{
int x;
cout<<"Enter a three digit number: ";
cin>>x;
cout<<"\tThere are\t: "<<x/100<<"\tHundreds\t"<<(x%100)/10<<"\tTens
and\t"<<x%10<<"\tOnes in the number\t: "<<x<<".";

return 0;
}

Task 2.4 Arithmetic Operators


Write a C++ program which takes two integer values from user and displays one as the percentage of other.
The output of your program should be as below. Indent your code and include comments for improving the
readability of your code.

Enter the first number: 30


Enter the second number : 40
30 is equal to 75.00% of 40.

11 CPS 110 Fundamentals of Programming C++ Building Blocks II


Solution :

#include<iostream>
using namespace std;
int main()

{
float x,y,z;
cout<<"Enter First Number: ";
cin>>x;

cout<<"\nEnter Second Number: ";


cin>>y;

z=(x/y)*100;

cout<<"\n"<<x<<" is equal to the "<<z<<"% of "<<y<<".";

return 0;
}

Task 2.5 Increment and Decrement Operators


Write a C++ program which prompts the user to enter an integer value, stores it into a variable called num,
evaluates the following expressions and displays results on screen.
num+5, num-3, (num+3) 2, ((num+5)*2 / (num+3))
For performing addition and subtraction, you are allowed to use ONLY the increment and decrement
operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement
operators changes the original value of a number. Indent your code and include comments for improving the
readability of your code. Your program should have the following interface.

Enter a number : 20
20 + 5 = 25
20 3 = 17
(20 + 3)- 2 = 21
((20 + 5)*2 / (20 + 3)) = 2

12 CPS 110 Fundamentals of Programming C++ Building Blocks II


POST-Lab Task # 2.1
(Algebraic Expressions Calculator in C++)
Total Marks : 10
Write a C++ program which prompts the user to enter two integer values, stores them in variables named a
and b, calculates the following expressions and displays the results on screen. Output of your program
must be presentable. You must use minimum possible number of parentheses for evaluating these
expressions.
1. (a + b)2 = a2 + 2ab + b2
2. (a - b)2 = a2 - 2ab + b2
3. (a + b)3 = a3 + 3a2b + 3ab2 + b3
4. (a - b)3 = a3 - 3a2b + 3 ab2 - b3
5. a2 - b2 = (a - b) (a + b)
6. a3 - b3 = (a - b)3 + 3 a b (a - b)
7. a3 - b3 = (a - b) (a2 + a b + b2)
8. a3 + b3 = (a + b) (a2 - a b + b2)
9. a3 + b3 = (a + b)3 - 3 a b (a + b)

Web Resources

http://www.cplusplus.com/doc/tutorial/

13 CPS 110 Fundamentals of Programming C++ Building Blocks II


EXPERIMENT 3 C++ CONTROL STRUCTURES-I

Learning Objectives
In todays lab, you will practice;
1. Using one-way selection structure (if).
2. Using two-way selection structure (if/else).
3. Using multiple selection structure (switch).

Practice Questions
You can practice the following problems in this lab.
Task 3.1 if Statement
Write a C++ program which takes two numbers from the user and tells which number is greater. Your output
should be as below.

Enter the first number : 25


Enter the second number : 32
First number is 25 and second number is 32.
Second number is greater.

Task 3.2 if/else Statement


Write a C++ program which takes five numbers from the user and finds the largest of these numbers. Your
output should be as below.

Enter the first number : 25


Enter the second number : 32
Enter the third number : 12
Enter the fourth number : 85
Enter the fifth number : 53
The largest of the 5 numbers is 85.

Task 3.3 if/else Statement


Write a C++ program which generates Grades for students depending on their Scores. Here is the criterion
for awarding Grades.
If Score is between 85 -100, Grade is A
If Score is between 72 - 84, Grade is B
If Score is between 60 - 71, Grade is C
If Score is between 50 - 59, Grade is D
If Score is between 0 - 49, Grade is F (F Grade indicates that the student has failed.)

14 CPS 110 Fundamentals of Programming C++ Control Structures I


For all other values of Score entered by user, your program should print Invalid Score was entered. No
Grade can be generated. The output of your program should be as below.

Enter students score : 67


The student passed in C Grade.

Enter students score : 43


The student has failed with F Grade.

Task 3.4 switch Statement


Repeat Task 3.3 using switch statement.

Task 3.5 if/else Statement


Write a C++ program which takes a character input from user and tells if it is a digit or not. If it is a digit,
your program should tell if it is even or odd. If it is not a digit, your program should tell if it is an alphabet
or not. If it is an alphabet, your program should tell if it is uppercase or lowercase. If it is not an alphabet,
your program should print It is a special symbol. The output of your program should be as below.

Enter a value : 7
It is an odd digit.

Enter a value : H
It is an alphabet in UPPERCASE.

Enter a value : f
It is an alphabet in lowercase.

Enter a value : *
It is a special symbol.

15 CPS 110 Fundamentals of Programming C++ Control Structures I


POST-Lab Task # 3.1
(Calculator in C++)
Total Marks : 10
Write a C++ program which performs five basic arithmetic operations (+, -, *, /, %). Your program should
prompt the user to enter two integers and once character, where the character variable will indicate the
specific arithmetic operation to be performed. Your program should have the following interface. In the
following example, 5 and 7 are the two integers and + is the character value entered by the user. Based on
the value of this character variable, your program should perform the appropriate arithmetic operation. You
have to write this program using both if/else and switch statements, one by one.
Output of your program must be presentable.

Enter the arithmetic expression to be evaluated:


5
+
7
5 + 7 = 12

POST-Lab Task # 3.2


(Auto Loan Calculator in C++)
Total Marks : 10
Company CarsNLoans offers car loans to its customers. Every year, the company spends thousands of
rupees for printing the tariff brochures. It is now planning to cut down on this expenditure by making a
small computer application available to its customers using which the customers can calculate the monthly
installment rates. You have been asked to write a C++ code for this application. Your program should
prompt the user to enter values of the following parameters.
Vehicle Price (Total cost of car)
Down Payment (First payment made while purchasing the car)
Installment Months (Number of months for which loan is required)

Here is the method to calculate Monthly Installments.


Payable Amount = Vehicle Price Down Payment
New Payable Amount = (Payable Amount + (Payable Amount * Interest Rate))
Monthly Installment = New Payable Amount / Installment Months

Interest Rate is applicable as below;


Installment Months Interest Rate
Less than or equal to 12 10% of Payable amount
Greater than 12 and less than or equal to 24 15% of Payable amount
Greater than 24 and less than or equal to 36 20% of Payable amount
Greater than 36 and less than or equal to 48 25% of Payable amount
Greater than 48 and less than or equal to 60 30% of Payable amount

16 CPS 110 Fundamentals of Programming C++ Control Structures I


Your program should have the following interface.
Enter the Vehicle Price in rupees : 800000
Enter the Down Payment in rupees : 300000
For how many months, do you want to lease the car : 36
Your Monthly Installment is : Rs.16666.7

Web Resources

http://math.about.com/od/businessmath/ss/Interest_2.htm
http://www.tutorialspoint.com/cplusplus/

17 CPS 110 Fundamentals of Programming C++ Control Structures I


EXPERIMENT 4 C++ CONTROL STRUCTURES-II

Learning Objectives
In todays lab, you will practice;
1. Using for repetition structure.
2. Using while repetition structure.
3. Using do/while repetition structure.

Practice Questions
You can practice the following problems in this lab.
Task 4.1 for Statement
Write a C++ program which takes an integer input from the user, prints all even and odd integers less than
or equal to this number and greater than or equal to1, calculates the sum of these even and odd integers
separately and displays results on the screen. Your program should have the following interface.

Enter a number : 7
Odd numbers less than or equal to 7 are :
1 , 3 , 5, 7
Even numbers less than or equal to 7 are :
2 , 4 , 6

Sum of odd numbers : 16


Sum of even numbers : 12

Task 4.2 while Statement


Write a C++ program which prompts the user to enter a float value, repeatedly prints the value of this
floating point variable, decreasing it by 0.5 each time, as long as its value remains greater than or equal to 0.
Your program should have the following interface.

Enter any float value : 2.5


2.5
2.0
1.5
1.0
0.5
0

18 CPS 110 Fundamentals of Programming C++ Control Structures II


Task 4.3 do/while Statement
Write a C++ program which takes an integer input from the user, calculates the factorial of this number
using do/while statement and displays the result on screen. Your program should have the following
interface.
Enter any value to calculate its Factorial: 5
Factorial of 5 is : 120

Task 4.4 for Statement


Write a C++ program which takes an integer input from user in the variable named num, calculates the
sum of all integers from 1 to num and displays this sum on screen. Your program should have the
following interface.

Enter any value : 10


Sum of integers from 1 to 10 is : 55

Task 4.5 while Statement


The Greatest Common Divisor (GCD) of two integers is the largest integer that evenly divides both the
numbers. Write a C++ program that returns the GCD of two numbers entered by the user. Your program
should have the following interface.

Enter the first number : 35


Enter the second number : 45
GCD of 35 and 45 is : 5

19 CPS 110 Fundamentals of Programming C++ Control Structures II


POST-Lab Task # 4.1
Total Marks : 5 + 5 + 5 + 5 + 5
Repeat Task 4.1 using while and do/while statements. Repeat Task 4.2 using for and do/while
statements. Repeat Task 4.3 using for and while statements. Repeat Task 4.4 using while and do/while
statements. Repeat Task 4.5 using for and do/while statements.

Web Resources

http://www.tutorialspoint.com/cplusplus/
http://www.learncpp.com/

20 CPS 110 Fundamentals of Programming C++ Control Structures II


EXPERIMENT 5 C++ CONTROL STRUCTURES-III

Learning Objectives
In todays lab, you will practice;
1. Using nested for repetition structure.
2. Using nested while repetition structure.
3. Using nested do/while repetition structure.
4. Using nesting of different control structures.

Practice Questions
You can practice the following problems in this lab.
Task 5.1 Nested for Statement
Write a C++ Program which displays hours, minutes and seconds from 01:00:00 to 10:00:00. You can
display the time using a delay of one second. Find out how you can do it and use it in your program. Your
program should have the following interface.
01:00:00
01:00:01
01:00:02
:
:

Task 5.2 Nested while Statement


Repeat Task 5.1 using nested while loop.

Task 5.3 Nested for Statement


Write a C++ program to implement a counter which can count from 000000000 to 999999999. You will
have to use 9 nested for loops to generate the output.

21 CPS 110 Fundamentals of Programming C++ Control Structures II


Task 5.4 Nested do/while Statement
Write a C++ program to read an odd integer from the user. If the user enters an even number, your program
should decrement it by one to generate an odd number. Using this number as the number of rows, your
program should then display a diamond of *s on screen. Your program should have the following interface.

Enter an odd number : 5


*
***
*****
***
*

POST-Lab Task # 5.1


Total Marks : 10
Write a C++ program to produce the following multiplication table. You must use nesting of control
structures.
1 2 3 4 5 6 7 8 9 10 11 12

2 4 6 8 10 12 14 16 18 20 22 24

3 6 9 12 15 18 21 24 27 30 33 36

4 8 12 16 20 24 28 32 36 40 44 48

5 10 15 20 25 30 35 40 45 50 55 60

6 12 18 24 30 36 42 48 54 60 66 72

7 14 21 28 35 42 49 56 63 70 77 84

8 16 24 32 40 48 56 64 72 80 88 96

9 18 27 36 45 54 63 72 81 90 99 108

10 20 30 40 50 60 70 80 90 100 110 120

11 22 33 44 55 66 77 88 99 110 121 132

12 24 36 48 60 72 84 96 108 120 132 144

22 CPS 110 Fundamentals of Programming C++ Control Structures II


POST-Lab Task # 5.2
Total Marks : 10
Write a C++ program to print first 100 prime numbers on screen.

POST-Lab Task # 5.3


Total Marks : 10
Write a C++ program which reads in a number from user, stores it in a variable named N and calculates the
sum of powers using the following formula.

Sum = 11 + 22 + 33 ++NN

Your program should have the following interface.

Enter a number : 4
Sum = 1^1 + 2^2 + 3^3 + 4^4 = 288

Web Resources

http://www.tutorialspoint.com/cplusplus/
http://www.learncpp.com/

23 CPS 110 Fundamentals of Programming C++ Control Structures II


EXPERIMENT 6 C++ LANGUAGE AND FUNCTIONS-I

Learning Objectives
In todays lab, you will practice;
1. Writing functions which take no arguments.
2. Writing functions which take one or more arguments.
3. Writing functions which do not return a value.
4. Writing functions which return a value.

Practice Questions
You can practice the following problems in this lab.
Task 6.1 Functions with No Arguments/One Argument
Write a function called separator in C++ language which prints 15 *s in a single line. Write another
function named multiples that takes an integer as an argument and prints its multiples up to ten terms,
separated by spaces, in a single line. Write a C++ program which takes an integer N from user and calls
these two functions to generate tables of all numbers between 1 to N. Your program should have the
following interface.

Enter the value of N : 4


The tables from 1 to 4 are :
1 2 3 4 5 6 7 8 9 10
* * * * * * * * * * * * * * *
2 4 6 8 10 12 14 16 18 20
* * * * * * * * * * * * * * *
3 6 9 12 15 18 21 24 27 30
* * * * * * * * * * * * * * *
4 8 12 16 20 24 28 32 36 40

24 CPS 110 Fundamentals of Programming C++ Language and Functions I


Task 6.2 Functions with a Return Value
An integer is said to be a Perfect Number if the sum of its divisors, including 1 (but not itself), is equal to
that number. For example, 6 is a perfect number, because 6 = 1+2+3. Write a C++ function called IsPerfect
that takes an integer as parameter and returns 1 if the passed integer is a perfect number and 0 if it not a
perfect number. Use this function in a C++ program that reads in an integer value from user into a variable
named N and prints all perfect numbers between 1 and N. Print the divisors of each perfect number to
confirm that the number is indeed a perfect number. Your program should have the following interface.

Enter a value for N : 30


Perfect numbers between 1 and 30 are :
6 Divisors are 1,2,3
28 Divisors are 1,2,4,7,14

Task 6.3 Functions with more than One Arguments


Write a function in C++ language that takes four integers as arguments and returns the largest of the four
numbers. Use this function in a C++ program which takes four integers from user and displays the largest on
screen. Your program should have the following interface.

Enter four integers :


25
32
57
41
The largest among 25,32,57,41 is 57.

Task 6.4 Functions with Arguments and a Return Value


25 CPS 110 Fundamentals of Programming C++ Language and Functions I
Write a function in C++ language that takes an integer num as argument and returns the sum of all
numbers between 1 to num. Use this function in a C++ program which takes an integer from user, stores it
in a variable named N and displays the result of the following function.

F(N) = 1 + (1+2) + (1+2+3) + ......+ (1+2+...N)

Your program should have the following interface.

Enter the value of N : 5


F(5)= 1 + 3 + 6 + 10 + 15 = 35

POST-Lab Task # 6.1


Total Marks : 10
Write functions in C++ language for calculating the area and perimeter of a square, circle and rectangle. Use
these functions in a C++ program which takes a character input (s for square, c for circle and r for
rectangle) from user and displays the area and perimeter of the corresponding shape. Your program should
prompt the user to enter lengths of sides based on the specific character entered by user. Your program
should have the following interface.

Enter the first letter of the shape : S


Enter the length of its sides in cms : 5
Area of this square is 25 sq.cms
Perimeter of this square is 20 cms

Web Resources

1. http://www.tutorialspoint.com/cplusplus/
2. http://www.learncpp.com/

26 CPS 110 Fundamentals of Programming C++ Language and Functions I


EXPERIMENT 7 C++ LANGUAGE AND FUNCTIONS-II

Learning Objectives
In todays lab, you will practice;
1. Writing overloaded functions.
2. Passing arguments by reference.
3. Writing macros.
4. Placing functions before and after main().

Practice Questions
You can practice the following problems in this lab.
Task 7.1 Function Overloading
Write a C++ program using function overloading. The name of the overloaded function is square. The
different prototypes of this overloaded function are;
void square(void); // Used to print a solid square of *s with side length of 5
void square (char); // Used to print a solid square of the character passed as argument with side
length of 6
void square(char, int); // Used to print a solid square of the character and the side length passed as
arguments to this function
Make calls to these functions one by one in your program.

Task 7.2 Passing by Reference


Write a function swap in C++ language that swaps the values of two variables passed as arguments to this
function. Write a C++ program which takes values of two integer variables from the user and swaps their
values using function swap. Your program should have the following interface.
Enter the first value : 6
Enter the second value : 9
The two numbers have been swapped.
The first number is now 9.
The second number is now 6.

27 CPS 110 Fundamentals of Programming C++ Language And Functions II


Task 7.3 Writing Macros
Write a C++ program which prompts the user to enter an integer, calculates the square and cube of this
number and prints them on screen. You must define macros for calculating squares and cubes. Your program
should have the following interface.
Enter a number : 6
The square of 6 is : 36
The cube of 6 is : 216

Task 7.4 Placement of Functions


Repeat Task 6.1, 6.2, 6.3 and 6.4 placing the defined functions before and after the main(). What difference
did you observe in both approaches with respect to the inclusion of function prototypes and function
definitions?

POST-Lab Task # 7.1


Total Marks : 10
Define a function named rightCircular using C++ language which takes in four integers as arguments and
rotates their values to right. For instance, if the parameter list consists of variables a,b,c,d and the passed
arguments are 2,8,3,7. After the function call, the respective values of a,b,c,d should be 7,2,8,3. Define
another similar function named leftCircular which rotates the values of the four passed arguments to left.
Write a C++ program which prompts the user to enter two characters and five integers in the following
order;
character, integer, integer, character, integer, integer, four digit integer

The values of character variables can either be l for left or r for right. The first integer after both
characters indicates the number of shifts required and the second one indicates the additive constant to be
added to each digit of the four digit integer supplied as the fifth input.

Your program should calculate the value and display result on screen. A sample output is given below. You
will have to separate the digits of the fifth input before passing them to circular shift functions.

Enter the input.


L
2
1
R
1
0
1234
The result is 3452

28 CPS 110 Fundamentals of Programming C++ Language And Functions II


1234 will be shifted left 2 (indicated by input # 1 and 2) times yielding (2341 -> 3412). All digits of this
number will now be incremented by the additive constant 1(indicated by input #3), thus yielding 4523. This
number will now be shifted right by 1 place (indicated by input # 4 and 5), thus yielding 3452. All digits of
this number will now be incremented by the additive constant 0(indicated by input #6), thus yielding 3452
as the final output.

Web Resources

1. http://www.cplusplus.com/doc/tutorial/

29 CPS 110 Fundamentals of Programming C++ Language And Functions II


EXPERIMENT 8 C++ LANGUAGE AND FUNCTIONS-III

Learning Objectives
In todays lab, you will practice;
1. Writing functions in separate header files and including them in your main file.
2. Using recursive functions.

Practice Questions
You can practice the following problems in this lab.
Task 8.1 Using Header Files
Repeat Task 6.1, 6.2, 6.3 and 6.4 placing the defined functions in separate header files.

Task 8.2 Using Recursive Functions


Define a recursive function named power which takes two parameters, base and exponent, and returns the
value equivalent to base multiplied by itself, exponent times. Define another recursive function factorial
which takes an integer as argument and returns the value equivalent to this numbers factorial. Use these
recursive functions in a C++ program which takes the values of x,y and N from user, calculates the
following functions and displays the results on screen.

F(x, y) = x/y x2/y2 + x3/y3 x4/y4 + + xN/yN

G(x) = x/1! x2/2! + x3/3! x4/4! + + xN/N!


Your program should have the following interface.
Enter the values of x,y and N.
3
2
3
F(3,2)= 2
G(3) = 3

Task 8.3 Using Recursive Functions


Write a recursive function named separator which takes two integer parameters and finds the quotient and
remainder when the first integer is divided by the second integer. Write a C++ program which takes an
integer input from the user, uses the function separator to separate the digits of this number and displays
the reverse of this number. Your program should have the following interface.

Enter a number : 3453


The number in reverse is : 3543

30 CPS 110 Fundamentals of Programming C++ Language and Functions III


POST-Lab Task # 8.1
Total Marks : 10
Write a recursive function that displays alphabets from Z to A. Use this function in a C++ program to verify
that your function works correctly.

POST-Lab Task # 8.2


Total Marks : 10
Write a recursive function that displays integers less than or equal to a specific number and greater than or
equal to 0, in descending order. Use this function in a C++ program which prompts the user to enter the
value of N and displays all integers from N to 0 in descending order.

Web Resources

1. http://www.cprogramming.com/

31 CPS 110 Fundamentals of Programming C++ Language and Functions III


EXPERIMENT 9 1-DIMENSIONAL ARRAYS-I

Learning Objectives
In todays lab, you will practice;
1. Declaring and initializing one-dimensional arrays.
2. Inserting values into and printing values out of one-dimensional arrays.

Practice Questions
You can practice the following problems in this lab.
Task 9.1 Declaring One-Dimensional Arrays
Write a C++ program, which declares;
Integer type array of 10 Indexes
Float type array of 15 Indexes
Double type array of 20 Indexes
Character type array of 25 Indexes
Your program should calculate and print the size of each array. Your program should have the following
interface.

Size of integer array of 10 indexes is : 40 Bytes


Size of float array of 15 indexes is : 60 Bytes
Size of double array of 20 indexes is : 160 Bytes
Size of character array of 25 indexes is : 25 Bytes

Task 9.2 Initializing and Printing One-Dimensional Arrays


Write a C++ program, which declares;

Integer type array of size 6. Initialize each index of array with 12 at the Time of Declaration.
Float type array of size 5. Initialize each index of array with 0.5 at the Time of Declaration.
Character type array of size 4. Initialize each index of array with a at the Time of Declaration.
Your program should display the values stored in these arrays using the following format.

Integer array : 12 12 12 12 12 12
Float array : 0.5 0.5 0.5 0.5 0.5
Character array : a a a a

32 CPS 110 Fundamentals of Programming 1 D Arrays I


Task 9.3 Inserting Values into and Printing Values out of One-Dimensional Arrays
Write a C++ program which prompts the user to enter integer, float and character values into the arrays
defined in Task 9.2. Your program should have the following interface. Do this task using for, while, and
do/while structures one by one.

Enter values into Integer Array:


Location [0] : 3
Location [1] : 4
Location [2] : 10
Location [3] : 102
Location [4] : 21
Location [5] : 968

Enter values into Float Array:


Location [0] : 3.5
Location [1] : 4.1
Location [2] : 1.8
Location [3] : 102.4
Location [4] : 21.3

Enter values into Character Array:


Location [0] : s
Location [1] : r
Location [2] : o
Location [3] : i

The Integer Array values are : 3, 4, 10, 102, 21, 968


The Float Array values are : 3.5, 4.1, 1.8, 102.4, 21.3
The Character Array values are : s, r, o, i

POST-Lab Task # 9.1


Total Marks : 10
Write a C++ program which declares two integer arrays of 5 indexes each, reads in integer values from user
into one of these arrays, copies the values of this array into the second array, reads values from the indexes
of the second array one by one and prints the respective number of *s on separate lines.

Web Resources

1. http://www.cprogramming.com/

33 CPS 110 Fundamentals of Programming 1 D Arrays I


EXPERIMENT 10 1-DIMENSIONAL ARRAYS-II

Learning Objectives
In todays lab, you will practice;
1. Traversing through one-dimensional arrays.
2. Passing one-dimensional arrays to functions.

Practice Questions
You can practice the following problems in this lab.
Task 10.1 Searching through One-Dimensional Arrays
Write a C++ program, which;
Declares and initializes an integer array of 15 indexes
Prompts the user to enter a number (integer value)
Searches through the array to find this number and
Prints the respective index numbers where the user specified number has been found
Your program should have the following interface.

Enter an integer value and Ill tell you if it exists in the


integer array or not : 34

34 has been found at index [5] [12] [13]

The integer array is :


90, 87, 23, 3, 8, 34, 67, 75, 1, 2, 3, 4, 34, 34, 2

Task 10.2 Traversing through One-Dimensional Arrays


Write a C++ program, which;
Declares and initializes an integer array of 20 indexes
Finds the minimum, maximum, sum and average of the elements of this array and
Prints these results on screen
Your program should have the following interface.

The integer array is :


90, 87, 23, 3, 8, 34, 67, 75, 45, 90,
1, 2, 3, 4, 34, 44, 4, 78, 56, 12
The minimum value is 1 found at index [10]
The maximum value is 90 found at index [0] [9]
The sum is 760
The average is 38

34 CPS 110 Fundamentals of Programming 1 D Arrays II


Task 10.3 Traversing through One-Dimensional Arrays
English alphabets a, e, i, o, u are called vowels. Alphabets that are not vowels are called consonants. Write a
C++ program, which takes a string input from user into a character array, counts the total number of vowels
and consonants in this array and prints the results on screen. Your program should have the following
interface.

Enter a string : Massachusetts


Vowel a appears 2 times
Vowel e appears 1 time
Vowel u appears 1 time
There are 9 consonants in this string.

Task 10.4 Traversing through One-Dimensional Arrays


Write a function in C++ which tests if two integer arrays have the same entries or not (even if not in the
same order). The function must return 1 if the two arrays have the same entries and return 0 otherwise. The
return type of your function should be bool. Use this function in your main program to find out if two
arrays have same entries or not and display results on screen. Your program should have the following
interface.
The first array is : 3 5 2 10 6
The second array is : 10 2 6 5 3
The two arrays have the same entries.

POST-Lab Task # 10.1


Total Marks : 10
35 CPS 110 Fundamentals of Programming 1 D Arrays II
Write a function in C++ language which takes two parameters as arguments, the first being an integer array
and the second being the size of this integer array, and sorts this integer array in descending order. Write a
similar function which takes the same arguments, but sorts the integer array in ascending order. Write a C++
program which takes integer values from user, inserts them into an integer array, uses these two functions to
sort the array in ascending and descending order and prints the results on screen. You can take any size of
the integer array.

POST-Lab Task # 10.2


Total Marks : 5 + 5
Do Tasks 10.1 and 10.2 by using functions. You must pass respective arrays to these functions as arguments.

Web Resources

1. http://www.cprogramming.com/
2. http://www.dreamincode.net/
3. http://www.learncpp.com/

36 CPS 110 Fundamentals of Programming 1 D Arrays II


EXPERIMENT 11 2-DIMENSIONAL ARRAYS-I

Learning Objectives
In todays lab, you will practice;
1. Declaring and initializing two-dimensional arrays.
2. Inserting values into and reading values out of two-dimensional arrays.
3. Traversing through two-dimensional arrays.

Practice Questions
You can practice the following problems in this lab.
Task 11.1 Declaring, Initializing and Printing Two-Dimensional Arrays
Write a C++ program which initializes a 7x7 float type array with 0 and then prints it on screen. Your
program should have the following interface.
The 7 X 7 array is :
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

Task 11.2 Storing Values into Two-Dimensional Arrays


Write a C++ program which declares a 2x4-integer type array, prompts the user to enter data into each
element of this array and then prints this array on screen. Your program should have the following interface.

Enter values for 2 rows and 4 columns.


Enter values for row 0 :
Location [0][0] : 1
Location [0][1] : 3
Location [0][2] : 6
Location [0][3] : 7
Enter values for row 1 :
Location [1][0] : 7
Location [1][1] : 9
Location [1][2] : 3
Location [1][3] : 2
Your stored data is :
1 3 6 7
7 9 3 2

37 CPS 110 Fundamentals of Programming 2 D Arrays I


Task 11.3 Traversing through Two-Dimensional Arrays
Write a C++ program which prompts the user to enter names of five countries, stores them into a two-
dimensional array, sorts them in alphabetical order and prints them on screen. Your program should have the
following interface.
Enter the names of five countries.
Pakistan
Afghanistan
Iran
Bangladesh
Turkey

The names of these countries in alphabetical order :


Afghanistan
Bangladesh
Iran
Pakistan
Turkey

POST-Lab Task # 11.1


Total Marks : 10
Write a C++ program which declares a 5 x 10 character array, prompts the user to enter string literals
(consisting of only alphabets) into this array and counts the value of each string (row). For counting value of
strings, assume a/A=1, b/B=2..z/Z=26. For instance, if the string at row 0 is hello, its value should be
calculated as (h = 8) + (e = 5) + ( l = 12) + (l = 12) + (o = 15) = 52. Once the values have been calculated,
your program should print the string with the highest value on screen.

Web Resources

1. http://www.tutorialspoint.com/cplusplus/
2. http://www.learncpp.com/
3. http://projectsyapa.com/cpp

38 CPS 110 Fundamentals of Programming 2 D Arrays I


EXPERIMENT 12 2-DIMENSIONAL ARRAYS-II

Learning Objectives
In todays lab, you will practice;
1. Traversing through two-dimensional arrays.
2. Passing two-dimensional arrays to functions.

Practice Questions
You can practice the following problems in this lab.
Task 12.1 Searching through Two-Dimensional Arrays
Write a C++ program, which
Populates a two-dimensional array of size 10 x 10 with random numbers between 0 and 9 (Hint: C++
has a built-in function for random number generation)
Prompts the user to enter a number
Searches for this number in the 10 x 10 array and
Displays location where the number is found in the array
Your program should display Value not found if the users specified number is not found in the 10 x
10 array. Your program should have the following interface.

Enter a value to find in the 10 x 10 array :


5
Found at location [0][5]
Found at location [1][9] In-Lab task # 11.5
Found at location [4][6]
Found at location [7][0]
4 instances found.

The 10 x 10 array is :
8 9 6 4 6 5 7 8 1 2
4 6 3 1 1 2 8 7 4 5
6 7 8 3 4 2 3 2 3 1
2 3 2 1 4 0 6 7 8 4
0 1 9 4 7 6 5 3 2 3
2 1 2 1 3 4 3 7 8 6
6 7 8 1 2 1 3 2 4 1
5 1 2 1 1 1 3 4 7 6
7 8 7 6 4 4 3 1 2 3
4 3 2 1 4 7 8 3 0 1

Task 12.2 Traversing through Two-Dimensional Arrays


39 CPS 110 Fundamentals of Programming 2 D Arrays II
Modify your C++ program for Task 12.1 such that the modified program searches through the array to find
maximum and minimum values and displays them with their respective location numbers. Your program
should have the following interface (Considering the array as populated in Task 12.1).

Minimum Value is : 0
Found at location [3][5]
Found at location [4][0]
Found at location [9][8]
3 instances found.

Maximum Value is : 9
Found at location [0][1]
Found at location [4][2]
2 instances found.

The 10 x 10 array is :
8 9 6 4 6 5 7 8 1 2
4 6 3 1 1 2 8 7 4 5
6 7 8 3 4 2 3 2 3 1
2 3 2 1 4 0 6 7 8 4
0 1 9 4 7 6 5 3 2 3
2 1 2 1 3 4 3 7 8 6
6 7 8 1 2 1 3 2 4 1
5 1 2 1 1 1 3 4 7 6
7 8 7 6 4 4 3 1 2 3
4 3 2 1 4 7 8 3 0 1

Task 12.3 Passing Two-Dimensional Arrays to Functions


Do Tasks 12.1 and 12.2 by using functions. You must pass respective arrays to these functions as arguments.

POST-Lab Task # 12.1


Total Marks : 10

40 CPS 110 Fundamentals of Programming 2 D Arrays II


Write a C++ program to simulate the tic-tac-toe game for a 3 x 3 grid. You will use a two-dimensional array
of size 3x3. Your program must include functions and you must pass your two-dimensional array to
functions as argument. If you dont know the rules of this game, read on it on Wikipedia.

Web Resources

1. http://en.wikipedia.org/wiki/Tic-tac-toe
2. http://www.tutorialspoint.com/cplusplus/
3. http://www.learncpp.com/

41 CPS 110 Fundamentals of Programming 2 D Arrays II


EXPERIMENT 13 POINTERS & STRINGS-I

Learning Objectives
In todays lab, you will practice;
1. Declaring and initializing pointers.
2. Using pointer arithmetic.
3. Passing pointer variables to functions.

Practice Questions
You can practice the following problems in this lab.
Task 13.1 Declaring and Initializing Pointers
Write a C++ program which creates pointer variables for the data types int, float, char and double, initializes
these pointers with the addresses of variables of respective data types and prints the size of pointer and the
data held by these pointers.

Task 13.2 Using Pointer Arithmetic


Write a C++ program which declares and initializes a character string with the string literal All is well, that
ends well., displays all distinct letters occurring in this string along with their corresponding frequencies
and displays special characters and symbols occurring in this string at the end of output. You are not
required to count lowercase and uppercase characters separately. Your program should have the following
interface.
Letter a found 2 times
Letter d found 1 time
Letter e found 3 times
Letter h found 1 time
Letter i found 1 time
Letter l found 6 times
Letter n found 1 time
Letter s found 2 times
Letter t found 2 times
Letter w found 2 times

Special symbols in this string are , .

Task 13.3 Passing Pointer Variables to Functions


42 CPS 110 Fundamentals of Programming Pointers and Strings I
Write a C++ function that takes a single string as its argument and returns a pointer to the first white space
character in the string. Use this function in a C++ program for printing all words of a string on separate
lines. Your program should have the following interface.

The string is: I am a student

It is displayed as :
I
am
a
student

POST-Lab Task # 13.1


Total Marks : 10
Write a C++ function that takes a single string as argument, removes all duplicate characters in the string
and returns the size of the modified string. Use this function in your main program to confirm that your
function works correctly.

Web Resources

1. http://en.wikipedia.org/wiki/Tic-tac-toe
2. www.cplusplus.com/doc/tutorial/pointers/
3. www.tutorialspoint.com/cplusplus/cpp_pointers.htm
4. www.youtube.com/watch?v=W0aE-w61Cb8

43 CPS 110 Fundamentals of Programming Pointers and Strings I


EXPERIMENT 14 POINTERS & STRINGS-II

Learning Objectives
In todays lab, you will practice;
1. Traversing through strings.
2. Passing pointer variables to functions.

Practice Questions
You can practice the following problems in this lab.
Task 14.1 Traversing through Strings
Write a C++ function called ReplaceNot that takes a string as a parameter, searches all three letter words in
the string passed as argument and replaces them with Not. Apply all the checks and cases. For example, if
the passed string is: Every boy has a pen. Your function should modify this string to: Every Not Not a
Not. Use this function in your main program to verify that your function works correctly.

Task 14.2 Passing Pointer Variables to Functions


Write a C++ function called ConvertToUpper that takes a string as a parameter, converts all lowercase
characters occurring in this string to uppercase and displays the modified string on screen. Use this function
in your main program to verify that your function works correctly.

Task 14.3 Passing Pointer Variables to Functions


Write a C++ function called ConvertToLower that takes a string as a parameter, converts all uppercase
characters occurring in this string to lowercase and displays the modified string on screen. Use this function
in your main program to verify that your function works correctly.

44 CPS 110 Fundamentals of Programming Pointers and Strings II


POST-Lab Task # 14.1
Total Marks : 20
You have seen some useful string manipulation functions included in the library header string.h. Some of
these functions include strcpy, strcmp, strcat and strlen Write C++ functions for implementing the
working of these functions using pointers. Use these functions in your main program to confirm that your
functions work correctly.

Web Resources

1. http://en.wikipedia.org/wiki/Tic-tac-toe
2. www.cplusplus.com/doc/tutorial/pointers/
3. www.tutorialspoint.com/cplusplus/cpp_pointers.htm
4. www.youtube.com/watch?v=W0aE-w61Cb8

45 CPS 110 Fundamentals of Programming Pointers and Strings II


EXPERIMENT 15 STRUCTURES

Learning Objectives
In todays lab, you will practice;
1. Declaring structures.
2. Traversing through structures.

Practice Questions
You can practice the following problems in this lab.
Phase 1 Declaring Structures
Write a C++ program for maintaining the library record of 100 books. Each record is composed of 6 fields
which include books library number, books name, authors name, edition number, year of publishing and
price of the book. Choose appropriate data types to represent each field. Your program should prompt the
user to populate 10 records of this database with some values and then print these values on screen. You
must use array of structures in your program. Your program should have the following interface.

Enter values for book 1 :


Books Name : A Guide to C Language Programming
Authors Name : XYZ
Edition Number : 1
Year of Publishing : 2013
Price of Book : 250

Phase 2 Traversing through Structures


Modify the C++ program for Task 15.1 such that the modified program prompts the user to enter an integer
from 1 to 6 (each number indicates a specific field of the library books records). Based on the specific
number entered, your program should ask the user to enter a specific value to search in the library database.
If the specific value is found, your program should display the corresponding record(s), otherwise it should
print No match found on the screen. Your program should have the following interface.

You can search for a specific book. Press an integer from 1 to


6 to specify the search item.
1. Books Library Number
2. Books Name
3. Authors Name
4. Edition Number
5. Year of Publishing
6. Price of Book

46 CPS 110 Fundamentals of Programming Structures


Assume the user enters the integer 3.

Enter the Authors Name :


XYZ

1 Book Found.
Book 1: A Guide to C Language Programming by XYZ, Edition 1
published in 2013. Price 250

POST-Lab Task # 15.1


Do Tasks 15.1 and 15.2 using pointers to structures. Your program should implement the operations to
modify existing records, delete existing records, add new records, sort and print the existing records with
respect to Authors Name in alphabetical order, sort and print the existing records with respect to Year of
Publishing in descending order, sort and print the existing records with respect to Price in ascending order.
You have to populate records for at least 15 books and demonstrate that your program works correctly.

Web Resources

1. www.cplusplus.com
2. msdn.microsoft.com/en-us/library/64973255.aspx
3. www.cprogramming.com/tutorial/lesson7.html

47 CPS 110 Fundamentals of Programming Structures


SEMESTER PROJECT

Total Marks : 10 Absolute


Maximum No of Students : 2

Write a C++ program to implement a traffic signal simulator and vehicle counter. Create a four way 3-lane
signal interchange and randomly generate traffic on each lane of each road. The program should support two
modes; Auto and Manual. In the Auto mode, the signals should operate automatically and move traffic
accordingly. In the Manual mode, user should be able to control the traffic signal. In this mode, user should
also be able to generate accidents by turning more than one signal green. Your program should also count
the number of vehicles going north, south, east and west and store these values in a file. The program should
have the following interface;

Phase 1 Interface Development


You have to create the interface. Roads should be black and rest of the screen area should be green. Letters
representing the traffic light should be the colour they represent (R should be red, Y should be yellow and G
should be green). When cars collide, they should blink. You can choose a grid of any size. Your program
should also let the user end the operations of simulator, and display a good bye screen at the end.
Deadline : 2 weeks after assignment

48 CPS 110 Fundamentals of Programming Project


Phase 2 Operations and File Handling
You have to implement the operations of the traffic signals simulator as described above. User should be
able to select a mode and your simulator should run accordingly. You have to store the number of vehicles
going in each direction, in a file. When the user quits the simulator, number of vehicles that have passed
through the signal in each direction should be displayed on the good bye screen.
Deadline: 2 weeks after assignment

Phase 3 Demo
You will be required to demonstrate your project in lab. Both group members must be present during demo.
Deadline : 1 week after assignment

Submission dates, submission instructions, policies and penalties for violation of policies will be discussed
in class.

49 CPS 110 Fundamentals of Programming Project


APPENDIX ASCII TABLE

50 CPS 110 Fundamentals of Programming Project


I hear and I forget,
I see and I remember,
I do and I understand

Confucius

Potrebbero piacerti anche