SlideShare ist ein Scribd-Unternehmen logo
1 von 7
F2037 PROGRAMMING FUNDAMENTAL OF C++


    LAB 1: VARIABLE, KEYWORD AND DATA TYPES

   Objectives

   By the end of this lab, students should be able to :
   • Describe the structure of C++ programmes
   • Write, compile and run simple C++ programmes
   • Identify and list keywords
   • List and define the various data types
   • Define variables and constants

   Theory/ Topics

   •   A program must have the function named main().
   •   Structure of C++ programmes
           o The structure of a simple C++ programme is
              similar to the structure of C.


         Structure                          Program
< Comment Entry>               // First C++ program

< Preprocessor directives >    #include <iostream>
                               #include <string>

main function                  int main()
 {                               {
 < declaration stat >;           int a;
 < C++ Statements >;             cout << "Welcome to
 }                                         Programming n”;
                                 return 0;
                                 }

   Table 1.1 : Structure of C++ Programme

       Consider the code in the given program:



                                                          1
F2037 PROGRAMMING FUNDAMENTAL OF C++


    1. // is used to comment a single line. In addition to //
         symbol, C++ supports /* */ for comment entry
         operation. /* */ is used to comment a set of
         statements.
    2.   #include <iostream> includes the header file for
         the program.
    3.   main() is the function where the program is written.
    4.   int a; is the variable declaration.
    5.   cout is used to display the output statements.
    6.   Every statement is terminated with a semi-colon,
         similar to C.

•   Keywords - have a strict meaning as individual tokens
    in C++. They cannot be redefined or used in other
    contexts.
•   Identifier - Sequence of letters, digits and the special
    character "_" which is called an underscore. A letter or
    underscore must be the first character of an identifier.

As C++ program is built from C, the C++ compiler supports
all the features of C.

The following are the steps involved in writing, compiling
and executing a C++ program :

    1. Open Microsoft Visual C++ and type the program.
    2. Save the file with the corresponding extension
       (filename.cpp)
    3. Compile the program.
    4. Build & execute/run the program.




                                                           2
F2037 PROGRAMMING FUNDAMENTAL OF C++


Lab 1A

Procedure :

Step 1: Type the programs given below
Step 2: Compile and run the program. Write the output.
Step 3: Save the program as lab1A.cpp.

The following program finds the sum of two numbers and
displays it.


// Program to add two numbers

#include <iostream>
using namespace std;

void main()
 {
 int a, b, sum;
 a = 5;
 b = 2;
 sum = a + b;
 cout << "The sum is: " << sum << "n";
 }


Lab 1B

Procedure :

Step 1: Type the programs given below
Step 2: Compile and run the program. Write the output.
Step 3: Change the statement cout << "The sum is: " <<
sum; in line 9 to cout << "The average is: " << sum/2;
Step 4: Save the program as lab1B.cpp.




                                                         3
F2037 PROGRAMMING FUNDAMENTAL OF C++


// Program to find the average of two numbers
#include <iostream>
using namespace std;

void main()
 {
 int a, b, sum;
 a = 5;
 b = 2;
 sum = a + b;
 cout << "The sum is: " << sum;
 }

Lab 1C

Procedure :

Step 1: Type the programs given below
Step 2: Compile and run the program. Write the output.
Step 3: Save the program as lab1C.cpp.

// The following program illustrates variable and
// constant declaration.

#include <iostream>
using namespace std;

const float PI = 3.14;

void main()
 {
 double radius = 3.0;
 double circumference;
 circumference = 2 * PI * radius;
 cout << "Circumference = " << circumference <<endl;
 }




                                                         4
F2037 PROGRAMMING FUNDAMENTAL OF C++


Lab 1D

Procedure :

Step 1: Type the programs given below
Step 2: Compile and run the program. Write the output.
Step 3: Save the program as lab1D.cpp.

// The following program illustrates variable and
// constant declaration.

#include <iostream>
#define PI 3.14
using namespace std;

void main()
  {
  double radius = 3.0;
  double circumference;
  circumference = 2 * PI * radius;
  cout << "Circumference = " << circumference <<endl;
 }

Lab 1E

Procedure :

Step 1: Type the programs given below
Step 2: Compile and run the program. Write the output.
Step 3: Save the program as lab1E.cpp.

Program to show the declaration and initialization of
variables with float, double, char, int and boolean data
type.

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

                                                         5
F2037 PROGRAMMING FUNDAMENTAL OF C++


 {
 char grade = 'F';
 float price = 77.01;
 double average = 145525.92;
 bool boolean_variable = true;
 int age = 50;
 cout << price <<"t"<< average <<"t"<<grade<<"t"<<
 boolean_variable <<"t"<<age<<endl;
 }

Lab 1F

Procedure :

Step 1: Type the programs given below
Step 2: Compile and run the program. Write the output.
Step 3: Save the program as lab1F.cpp.

Program to show the declaration and initialization of
variables with string data type.

// my first string
#include <iostream>
#include <string>
using namespace std;

void main ()
{
  string mystring = "This is a string";
  cout << mystring;
}




                                                         6
F2037 PROGRAMMING FUNDAMENTAL OF C++


   LAB EXERCISE

   1. Describe the functionality of using
      a. #include <string> as Preprocessor directives
      b. int main (void) as main function

   2. For each statement below, state either variable or
       constant and find a suitable variable and constant
       name
       a. the number of month in a year
       b. the sum of x + y if given x = 5 and y = 10

   3. Based on IPO chart information below:
      a. Declare the variable in C++ by using the
          appropriate data type
       b. Transform the Algorithm into C++ code

                    IPO Chart Information
Input                    Processing               Output
Number of late days = 7  Calculate amount         Display
Number of late charge =                           amount
0.2                      Algorithm
                         1. Declare the number
                             of late days, late
                             charges and
                             amount

                         2. Calculate the
                            amount by
                            multiplying the
                            number of late days
                            with late charge

                         3. Display amount




                                                            7

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
C++ book
C++ bookC++ book
C++ book
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in C
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Diff between c and c++
Diff between c and c++Diff between c and c++
Diff between c and c++
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
 
c++
 c++  c++
c++
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 

Andere mochten auch

Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++rohassanie
 
SSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In HindiSSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In Hindikusumafoundation
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesGuido Wachsmuth
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingHaris Bin Zahid
 
Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented languagefarhan amjad
 
Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Saurabh Singh Negi
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Languagedheva B
 
हिन्दी व्याकरण
हिन्दी व्याकरणहिन्दी व्याकरण
हिन्दी व्याकरणChintan Patel
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programmingNgeam Soly
 
OOPs concept and implementation
OOPs concept and implementationOOPs concept and implementation
OOPs concept and implementationSandeep Kumar P K
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
Working with and Leading People, Lecture 1
Working with and Leading People, Lecture 1Working with and Leading People, Lecture 1
Working with and Leading People, Lecture 1Rahat Kazmi
 
Vakya parichay
Vakya parichayVakya parichay
Vakya parichaysonia -
 

Andere mochten auch (20)

Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
SSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In HindiSSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In Hindi
 
Oops
OopsOops
Oops
 
Unit i
Unit iUnit i
Unit i
 
Oops Concepts
Oops ConceptsOops Concepts
Oops Concepts
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented language
 
Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
हिन्दी व्याकरण
हिन्दी व्याकरणहिन्दी व्याकरण
हिन्दी व्याकरण
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
 
OOPs concept and implementation
OOPs concept and implementationOOPs concept and implementation
OOPs concept and implementation
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
कारक
कारककारक
कारक
 
Working with and Leading People, Lecture 1
Working with and Leading People, Lecture 1Working with and Leading People, Lecture 1
Working with and Leading People, Lecture 1
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Vakya parichay
Vakya parichayVakya parichay
Vakya parichay
 

Ähnlich wie Labsheet1stud

Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************Emad Helal
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...bhargavi804095
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201rohassanie
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 studrohassanie
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itPushkarNiroula1
 
C Programming- Harsh Sharma
C Programming- Harsh SharmaC Programming- Harsh Sharma
C Programming- Harsh SharmaHarsh Sharma
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...RSathyaPriyaCSEKIOT
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)akmalfahmi
 

Ähnlich wie Labsheet1stud (20)

Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************
 
C++ Question
C++ QuestionC++ Question
C++ Question
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
2621008 - C++ 1
2621008 -  C++ 12621008 -  C++ 1
2621008 - C++ 1
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
C Programming- Harsh Sharma
C Programming- Harsh SharmaC Programming- Harsh Sharma
C Programming- Harsh Sharma
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 

Mehr von rohassanie

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012rohassanie
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6rohassanie
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2rohassanie
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5rohassanie
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2rohassanie
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1rohassanie
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3rohassanie
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2rohassanie
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2) rohassanie
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201rohassanie
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012rohassanie
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1rohassanie
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3 rohassanie
 

Mehr von rohassanie (20)

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Lab ex 1
Lab ex 1Lab ex 1
Lab ex 1
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
 
Labsheet 5
Labsheet 5Labsheet 5
Labsheet 5
 
Labsheet 4
Labsheet 4Labsheet 4
Labsheet 4
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 

Kürzlich hochgeladen

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 

Kürzlich hochgeladen (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

Labsheet1stud

  • 1. F2037 PROGRAMMING FUNDAMENTAL OF C++ LAB 1: VARIABLE, KEYWORD AND DATA TYPES Objectives By the end of this lab, students should be able to : • Describe the structure of C++ programmes • Write, compile and run simple C++ programmes • Identify and list keywords • List and define the various data types • Define variables and constants Theory/ Topics • A program must have the function named main(). • Structure of C++ programmes o The structure of a simple C++ programme is similar to the structure of C. Structure Program < Comment Entry> // First C++ program < Preprocessor directives > #include <iostream> #include <string> main function int main() { { < declaration stat >; int a; < C++ Statements >; cout << "Welcome to } Programming n”; return 0; } Table 1.1 : Structure of C++ Programme Consider the code in the given program: 1
  • 2. F2037 PROGRAMMING FUNDAMENTAL OF C++ 1. // is used to comment a single line. In addition to // symbol, C++ supports /* */ for comment entry operation. /* */ is used to comment a set of statements. 2. #include <iostream> includes the header file for the program. 3. main() is the function where the program is written. 4. int a; is the variable declaration. 5. cout is used to display the output statements. 6. Every statement is terminated with a semi-colon, similar to C. • Keywords - have a strict meaning as individual tokens in C++. They cannot be redefined or used in other contexts. • Identifier - Sequence of letters, digits and the special character "_" which is called an underscore. A letter or underscore must be the first character of an identifier. As C++ program is built from C, the C++ compiler supports all the features of C. The following are the steps involved in writing, compiling and executing a C++ program : 1. Open Microsoft Visual C++ and type the program. 2. Save the file with the corresponding extension (filename.cpp) 3. Compile the program. 4. Build & execute/run the program. 2
  • 3. F2037 PROGRAMMING FUNDAMENTAL OF C++ Lab 1A Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as lab1A.cpp. The following program finds the sum of two numbers and displays it. // Program to add two numbers #include <iostream> using namespace std; void main() { int a, b, sum; a = 5; b = 2; sum = a + b; cout << "The sum is: " << sum << "n"; } Lab 1B Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Change the statement cout << "The sum is: " << sum; in line 9 to cout << "The average is: " << sum/2; Step 4: Save the program as lab1B.cpp. 3
  • 4. F2037 PROGRAMMING FUNDAMENTAL OF C++ // Program to find the average of two numbers #include <iostream> using namespace std; void main() { int a, b, sum; a = 5; b = 2; sum = a + b; cout << "The sum is: " << sum; } Lab 1C Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as lab1C.cpp. // The following program illustrates variable and // constant declaration. #include <iostream> using namespace std; const float PI = 3.14; void main() { double radius = 3.0; double circumference; circumference = 2 * PI * radius; cout << "Circumference = " << circumference <<endl; } 4
  • 5. F2037 PROGRAMMING FUNDAMENTAL OF C++ Lab 1D Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as lab1D.cpp. // The following program illustrates variable and // constant declaration. #include <iostream> #define PI 3.14 using namespace std; void main() { double radius = 3.0; double circumference; circumference = 2 * PI * radius; cout << "Circumference = " << circumference <<endl; } Lab 1E Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as lab1E.cpp. Program to show the declaration and initialization of variables with float, double, char, int and boolean data type. #include <iostream> using namespace std; void main() 5
  • 6. F2037 PROGRAMMING FUNDAMENTAL OF C++ { char grade = 'F'; float price = 77.01; double average = 145525.92; bool boolean_variable = true; int age = 50; cout << price <<"t"<< average <<"t"<<grade<<"t"<< boolean_variable <<"t"<<age<<endl; } Lab 1F Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as lab1F.cpp. Program to show the declaration and initialization of variables with string data type. // my first string #include <iostream> #include <string> using namespace std; void main () { string mystring = "This is a string"; cout << mystring; } 6
  • 7. F2037 PROGRAMMING FUNDAMENTAL OF C++ LAB EXERCISE 1. Describe the functionality of using a. #include <string> as Preprocessor directives b. int main (void) as main function 2. For each statement below, state either variable or constant and find a suitable variable and constant name a. the number of month in a year b. the sum of x + y if given x = 5 and y = 10 3. Based on IPO chart information below: a. Declare the variable in C++ by using the appropriate data type b. Transform the Algorithm into C++ code IPO Chart Information Input Processing Output Number of late days = 7 Calculate amount Display Number of late charge = amount 0.2 Algorithm 1. Declare the number of late days, late charges and amount 2. Calculate the amount by multiplying the number of late days with late charge 3. Display amount 7