0% found this document useful (0 votes)
38 views

Lab2 PDF

This document provides instructions for Lab 2 in EECE 1313. It introduces a simple C++ program that prints "Hello World!" and then analyzes the components of the program. It discusses comments, header files, namespaces, and functions. It also lists 3 exercises - to write programs that accept currency amounts and display denominations, accept a character and display the next character, and accept days and convert to years/months/days. Students are asked to complete and submit the exercises by the end of the lab session.

Uploaded by

zarif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Lab2 PDF

This document provides instructions for Lab 2 in EECE 1313. It introduces a simple C++ program that prints "Hello World!" and then analyzes the components of the program. It discusses comments, header files, namespaces, and functions. It also lists 3 exercises - to write programs that accept currency amounts and display denominations, accept a character and display the next character, and accept days and convert to years/months/days. Students are asked to complete and submit the exercises by the end of the lab session.

Uploaded by

zarif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EECE 1313 LAB 2

28 SEPTEMBER 2016

NAME:

MATRIC NO.:

/* This program will illustrate different components of a simple


program in C++ */

#include <iostream>
using namespace std;

int main()
{
cout << "Hello World!";
return 0;
}

When the above program is compiled, linked and executed, the following
output is displayed on the VDU screen.
Hello World!
Various components of this program are discussed below:

Comments
First three lines of the above program are comments and are ignored by the
compiler. Comments are included in a program to make it more readable. If
a comment is short and can be accommodated in a single line, then it is
started with double slash sequence in the first line of the program. However,
if there are multiple lines in a comment, it is enclosed between the two
symbols /* and */

#include <iostream>
The line in the above program that start with # symbol are called directives
and are instructions to the compiler. The word include with '#' tells the
compiler to include the file iostream into the file of the above program. File
iostream is a header file needed for input/ output requirements of the
program. Therefore, this file has been included at the top of the program.
using namespace std;
All the elements of the standard C++ library are declared within std. This line
is very frequent in C++ programs that use the standard library.
int main ( )
The word main is a function name. The brackets ( ) with main tells that main
( ) is a function.
EXERCISE

1. Write a program which accepts amount as integer and display total number of Notes of
RM 500, 100, 50, 20, 10, 5 and 1.
For example, when user enter a number, 575, the results would be like this...
500: 1
100: 0
50: 1
20: 1
10: 0
5: 1
1: 0

2. Write a program which accepts a character and display its next character.
2. Write a program which accepts a character and display its next character.

3. Write a program which accepts days as integer and display total number of years, months
and days in it.
For example: If user input as 856 days the output should be 2 years 4 months 6 days.

*PLEASE SUBMIT YOUR WORK AT THE END OF THE LAB SESSION

You might also like