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

LAB ACTIVITY 1

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)
29 views

LAB ACTIVITY 1

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/ 7

DFC20113 PROGRAMMING FUNDAMENTALS – LAB ACTIVITY 1

LAB ACTIVITY 1:
INTRODUCTION TO FUNDAMENTALS OF
PROGRAMMING

Duration: 2 Hours

Learning Outcomes
This lab activity encompasses activities 1A and 1B

By the end of this practical session, you should be able to:

• Develop C++ program using Integrated Development Environment (IDE)


• Debug simple programs to demonstrate syntax/compile time, run time and logical
error

Hardware/Software: C++ software (Dev C++ or Microsoft Visual Studio or Turbo C++ 5.0/6.0)

Activity 1A

Activity Outcome: Write and compile a program using C++.


Duration : 30 minutes

Task 1: Follow the procedure below step by step.

PROCEDURE OUTPUT
Program 1:

Step 1: Type the programs given below

// Hello world program using C++

#include <iostream>
using namespace std;

// main() is where program execution begins.

int main()
{
cout << "Hello World"; // prints Hello World
return 0;
}
DFC20113 PROGRAMMING FUNDAMENTALS – LAB ACTIVITY 2

Step 2: Compile the program.


Step 3: Write the output.

Program 2:

Step 1: Type the programs given below

#include<iostream.h>
void main()
{
int a, b, sum;

cin >> a;
cin >> b;

sum = a + b;
cout << sum << endl;
}
Step 2: Compile the program.
Step 3: Write the output.

Program 3:

Step 1: Type the programs given below

// operating with variables

#include <iostream>
using namespace std;

int main ()
{
// declaring variables:
int a, b;
int result;

// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;

// print out the result:


cout << result;

// terminate the program:


return 0;
}
Step 2: Compile the program.
Step 3: Write the output.
DFC20113 PROGRAMMING FUNDAMENTALS – LAB ACTIVITY 3

Program 4:

Step 1: Type the programs given below


// input/output example

#include <iostream>
using namespace std;

int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << ".\n";
return 0;
}
Step 2: Compile and run the program.
Step 3: Write the output.

Program 5 :
//The following program displays string using
appropriate header file.

Step 1: Type the programs given below


#include <iostream>
#include <string>
using namespace std;
int main ()
{
string mystring = "This is a string";
cout << mystring;
return 0;
}
Step 2: Compile and run the program.
Step 3: Write the output.
DFC20113 PROGRAMMING FUNDAMENTALS – LAB ACTIVITY 4

Activity 1B
Activity Outcome: Detect the errors in following programs. Write the correct answers, compile
and run a program using C++
Duration : 60 minutes

Task 3 : Miss Suria has provided you with extra tasks. Follow the procedure below step by step.

PROCEDURE OUTPUT
Program 1 :

Step 1: Find the errors in following programs.

#include “iostream”

using namespace std;

int main
{
char name[50];

cout >> "Please enter your name: ";


cin <<name;
cout << Your name is: " name << endl;

}
Step 2: Write the correct answers
Step 3: Compile and run the program.
Step 4: Write the output.

Program 2 :

Step 1: Find the errors in following programs.

/ my second program in C++

include <iostream>
using namespace std;

int main ()
{
cout << Hello World!
cout >> "I'm a C++ program";
}
Step 2: Write the correct answers
Step 3: Compile and run the program.
Step 4: Write the output.
DFC20113 PROGRAMMING FUNDAMENTALS – LAB ACTIVITY 5

Program 3 :

Step 1: Find the errors in following programs.

#include <iostream>
using namespace std;

main()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;
}
Step 2: Write the correct answers
Step 3: Compile and run the program.
Step 4: Write the output.

Program 4 :

Step 1: Find the errors in following programs.

#include <iostream>
using namespace std;

#define LENGTH 10
#define WIDTH 5
#define NEWLINE '\n'

int main
{

int area

area = LENGTH * WIDTH;


cout >> area;
cout >> NEWLINE;
return 0;
}
Step 2: Write the correct answers
Step 3: Compile and run the program.
Step 4: Write the output.
DFC20113 PROGRAMMING FUNDAMENTALS – LAB ACTIVITY 6

Program 5 :

Step 1: Find the errors in following programs.

#include <iostream>
using namespace std;

main()
{
int a = 21
int b = 10;
int c ;

if( a == b )
{
cout << "Line 1 - a is equal to b" << endl
}
else
{
cout << "Line 1 - a is not equal to b" << endl
}
if ( a < b )
{
cout << "Line 2 - a is less than b" << endl
}
else
{
cout << "Line 2 - a is not less than b" << endl
}
if ( a > b )
{
cout << "Line 3 - a is greater than b" << endl
}
else
{
cout << "Line 3 - a is not greater than b" << endl
}

Step 2: Write the correct answers


Step 3: Compile and run the program.
Step 4: Write the output.
DFC20113 PROGRAMMING FUNDAMENTALS – LAB ACTIVITY 7

Program 6 :

Step 1: Find the errors in following programs.

#include <iostream>
using namespace std;

main()
{
a = 21;
b = 10;
c;

c = a + b;
cout >> "Line 1 - Value of c is :" << c << endl ;
c = a - b;
cout >> "Line 2 - Value of c is :" << c << endl ;
c = a * b;
cout >>"Line 3 - Value of c is :" << c << endl ;
c = a / b;
cout >> "Line 4 - Value of c is :" << c << endl ;
c = a % b;
cout >> "Line 5 - Value of c is :" << c << endl ;
c = a++;
cout >> "Line 6 - Value of c is :" << c << endl ;
c = a--;
cout >> "Line 7 - Value of c is :" << c << endl ;
return 0;
}
Step 2: Write the correct answers
Step 3: Compile and run the program.
Step 4: Write the output.

You might also like