SlideShare una empresa de Scribd logo
1 de 5
FP 201 PROGRAMMING FUNDAMENTAL


LAB 2: OPERATORS AND EXPRESSION

Learning Outcome:

By the end of this lab, students should be able to:
         Understand operators, operator’s precedence and expression.


Theory/ Topics

        A simple C++ program is similar to a C program. In C++ programs the statements to be executed are
contained inside the function.

        In operators and expressions, student must know about:
a)Arithmetic operators ( +, -, *, /, % )
     The five arithmetical operations supported by the C++ language are:
                                                 + addition
                                                 - subtraction
                                                 * multiplication
                                                 / division
                                                 % modulus

b)Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)

c) Increment and decrement (++, --)
Shortening even more some expressions, the increase operator (++) and the decrease operator (--) increase or reduce
by one the value stored in a variable. They are equivalent to +=1 and to -=1, respectively.

                                        Example 1                      Example 2
                               B=3;                          B=3;
                               A=++B;                        A=B++;
                               // A contains 4, B contains 4 // A contains 3, B contains 4


d)         Relational and equality operators (==, !=, >, <, >=, <= )
In order to evaluate a comparison between two expressions we can use the relational and equality operators. The
result of a relational operation is a Boolean value that can only be true or false, according to its Boolean result.

e)         Logical operators ( !, &&, || )
The Operator ! is the C++ operator to perform the Boolean operation NOT, it has only one operand, located at its
right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its
operand is false. Basically, it returns the opposite Boolean value of evaluating its operand.

                   Precedence of operators
When writing complex expressions with several operands, we must follow the precedence which is what operand is
evaluated first and which later. For example, in this expression:

                                                       a=5+7%2

                   7%2 is evaluated first, then followed by operator +
FP 201 PROGRAMMING FUNDAMENTAL


Activity 2A

Procedure :

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

#include <iostream>
using namespace std;
int main()
{
int class1 = 100;
int class2 = 200;
int class3 = 300;
int class4 = 400;
int class5 = 500;
int sum = 0;

double average;
sum = class1 + class2 + class3 + class4 + class5;
average = sum/5;
cout << " Sum = " << sum << endl;
cout << " Average = " << average << endl;
return 0;
}

Activity 2B

Procedure :

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

#include <iostream>
using namespace std;

void main()
{
        int x = 180, y = 200;
        y = x++;
        cout << " x : " << x << endl << " y : " << y << endl;
}


Activity 2C

Procedure :

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

#include <iostream>
using namespace std;
FP 201 PROGRAMMING FUNDAMENTAL



void main()
{
        int x = 180, y = 200;
        y = ++ x;
        cout << " x : " << x << endl << " y : "<< y << endl;
}


Activity 2D

Procedure :

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

#include <iostream>
using namespace std;

void main()
{
        double p = 12.5;
        double q = 3.234;
        p *= q - 1;
        q += p + 1;
        cout << " p is " << p << endl << " q is " << q << "n";
}


Lab 2E

Procedure :

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

         // Demonstrate the modulus operator.
         #include <iostream>
         using namespace std;
         int main()
         {
         int x, y;
         x = 10;
         y = 3;
         cout << x << " / " << y << " is " << x / y << " with a remainder of " << x % y << "n";

         x = 1;
         y = 2;
         cout << x << " / " << y << " is " << x / y << "n" << x << " % " << y << " is " << x % y;
         return 0;
         }
FP 201 PROGRAMMING FUNDAMENTAL


Lab 2F

Procedure :

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

// Demonstrate the relational and logical operators.
#include <iostream>
using namespace std;
int main()
{
int i, j;
bool b1, b2;
i = 10;
j = 11;
if(i < j) cout << "i < jn";
if(i <= j) cout << "i <= jn";
if(i != j) cout << "i != jn";
if(i == j) cout << "this won't executen";
if(i >= j) cout << "this won't executen";
if(i > j) cout << "this won't executen";

b1 = true; b2 = false;
if(b1 && b2) cout << "this won't executen";
if(!(b1 && b2)) cout << "!(b1 && b2) is truen";
if(b1 || b2) cout << "b1 || b2 is truen";
return 0;
}


Lab 2G

Procedure :

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

#include<iostream>
using namespace std;

void main()
{
        int i;
        for(i=1;i<=10;i++)
        cout<<i<<" /2 is: " << (float) i/2 << "n";
}
FP 201 PROGRAMMING FUNDAMENTAL


LAB EXERCISE

1.     Write the C++ expression for the following mathematical statement

a.         y=(x-2)(x+3)
b.         min = a + b + c + d + e
                         5                                                     (2 marks)

2.     Given the values x=5, y=5 and c=3. Write a program to calculate the value of z and display the output of z

       z = xy % c + 10 / 2y + 5;           (4 marks)

3.     Based on the flowchart, find the values for a and b. Write a program to calculate the values and display the
       output                                                                  (4 marks)


                         start

                  x=12, y=8,z=5


                      a=x*y-z

                b = (6*a/2+3-z)/2


                    print a,b


                         end

CONCLUSION
_____________________________________________________________________________________________
_____________________________________________________________________________________________
_____________________________________________________________________________________________
________________________________

Más contenido relacionado

La actualidad más candente

Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Himanshu Kaushik
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operatorSAFFI Ud Din Ahmad
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++sanya6900
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritancezindadili
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in CPrabhu Govind
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programmingprogramming9
 

La actualidad más candente (19)

Pointers
PointersPointers
Pointers
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 
Coper in C
Coper in CCoper in C
Coper in C
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Functions
FunctionsFunctions
Functions
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritance
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
Exam for c
Exam for cExam for c
Exam for c
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 

Destacado

Destacado (8)

Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Labsheet 5
Labsheet 5Labsheet 5
Labsheet 5
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
 
Labsheet 4
Labsheet 4Labsheet 4
Labsheet 4
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
 

Similar a Labsheet2 stud

FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
Esg111 midterm review
Esg111 midterm reviewEsg111 midterm review
Esg111 midterm reviewmickeynickey1
 
Oop with c++ notes unit 01 introduction
Oop with c++ notes   unit 01 introductionOop with c++ notes   unit 01 introduction
Oop with c++ notes unit 01 introductionAnanda Kumar HN
 
C++ Programming.pdf
C++ Programming.pdfC++ Programming.pdf
C++ Programming.pdfMrRSmey
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALPrabhu D
 
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions ManualNumerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions Manualwebavaq
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4Abdul Haseeb
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariTHE NORTHCAP UNIVERSITY
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in cSaranya saran
 

Similar a Labsheet2 stud (20)

Lab 1
Lab 1Lab 1
Lab 1
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
 
C++ Question
C++ QuestionC++ Question
C++ Question
 
901131 examples
901131 examples901131 examples
901131 examples
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Esg111 midterm review
Esg111 midterm reviewEsg111 midterm review
Esg111 midterm review
 
Oop with c++ notes unit 01 introduction
Oop with c++ notes   unit 01 introductionOop with c++ notes   unit 01 introduction
Oop with c++ notes unit 01 introduction
 
C++ Programming.pdf
C++ Programming.pdfC++ Programming.pdf
C++ Programming.pdf
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions ManualNumerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4
 
Programming in C
Programming in CProgramming in C
Programming in C
 
ICP - Lecture 5
ICP - Lecture 5ICP - Lecture 5
ICP - Lecture 5
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
 
random test
random testrandom test
random test
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 

Más de 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 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
 
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
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3rohassanie
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2rohassanie
 
Chapter 1 part 1
Chapter 1 part 1Chapter 1 part 1
Chapter 1 part 1rohassanie
 

Más de 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 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)
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
 
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
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2
 
Chapter 1 part 1
Chapter 1 part 1Chapter 1 part 1
Chapter 1 part 1
 
Unit 3
Unit 3Unit 3
Unit 3
 

Último

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Último (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Labsheet2 stud

  • 1. FP 201 PROGRAMMING FUNDAMENTAL LAB 2: OPERATORS AND EXPRESSION Learning Outcome: By the end of this lab, students should be able to: Understand operators, operator’s precedence and expression. Theory/ Topics A simple C++ program is similar to a C program. In C++ programs the statements to be executed are contained inside the function. In operators and expressions, student must know about: a)Arithmetic operators ( +, -, *, /, % )  The five arithmetical operations supported by the C++ language are: + addition - subtraction * multiplication / division % modulus b)Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=) c) Increment and decrement (++, --) Shortening even more some expressions, the increase operator (++) and the decrease operator (--) increase or reduce by one the value stored in a variable. They are equivalent to +=1 and to -=1, respectively. Example 1 Example 2 B=3; B=3; A=++B; A=B++; // A contains 4, B contains 4 // A contains 3, B contains 4 d) Relational and equality operators (==, !=, >, <, >=, <= ) In order to evaluate a comparison between two expressions we can use the relational and equality operators. The result of a relational operation is a Boolean value that can only be true or false, according to its Boolean result. e) Logical operators ( !, &&, || ) The Operator ! is the C++ operator to perform the Boolean operation NOT, it has only one operand, located at its right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its operand is false. Basically, it returns the opposite Boolean value of evaluating its operand. Precedence of operators When writing complex expressions with several operands, we must follow the precedence which is what operand is evaluated first and which later. For example, in this expression: a=5+7%2 7%2 is evaluated first, then followed by operator +
  • 2. FP 201 PROGRAMMING FUNDAMENTAL Activity 2A Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as Lab2A.cpp. #include <iostream> using namespace std; int main() { int class1 = 100; int class2 = 200; int class3 = 300; int class4 = 400; int class5 = 500; int sum = 0; double average; sum = class1 + class2 + class3 + class4 + class5; average = sum/5; cout << " Sum = " << sum << endl; cout << " Average = " << average << endl; return 0; } Activity 2B Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as Lab2B.cpp. #include <iostream> using namespace std; void main() { int x = 180, y = 200; y = x++; cout << " x : " << x << endl << " y : " << y << endl; } Activity 2C Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as Lab2C.cpp. #include <iostream> using namespace std;
  • 3. FP 201 PROGRAMMING FUNDAMENTAL void main() { int x = 180, y = 200; y = ++ x; cout << " x : " << x << endl << " y : "<< y << endl; } Activity 2D Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as Lab2D.cpp. #include <iostream> using namespace std; void main() { double p = 12.5; double q = 3.234; p *= q - 1; q += p + 1; cout << " p is " << p << endl << " q is " << q << "n"; } Lab 2E Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as Lab2E.cpp. // Demonstrate the modulus operator. #include <iostream> using namespace std; int main() { int x, y; x = 10; y = 3; cout << x << " / " << y << " is " << x / y << " with a remainder of " << x % y << "n"; x = 1; y = 2; cout << x << " / " << y << " is " << x / y << "n" << x << " % " << y << " is " << x % y; return 0; }
  • 4. FP 201 PROGRAMMING FUNDAMENTAL Lab 2F Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as Lab2F.cpp. // Demonstrate the relational and logical operators. #include <iostream> using namespace std; int main() { int i, j; bool b1, b2; i = 10; j = 11; if(i < j) cout << "i < jn"; if(i <= j) cout << "i <= jn"; if(i != j) cout << "i != jn"; if(i == j) cout << "this won't executen"; if(i >= j) cout << "this won't executen"; if(i > j) cout << "this won't executen"; b1 = true; b2 = false; if(b1 && b2) cout << "this won't executen"; if(!(b1 && b2)) cout << "!(b1 && b2) is truen"; if(b1 || b2) cout << "b1 || b2 is truen"; return 0; } Lab 2G Procedure : Step 1: Type the programs given below Step 2: Compile and run the program. Write the output. Step 3: Save the program as Lab2G.cpp. #include<iostream> using namespace std; void main() { int i; for(i=1;i<=10;i++) cout<<i<<" /2 is: " << (float) i/2 << "n"; }
  • 5. FP 201 PROGRAMMING FUNDAMENTAL LAB EXERCISE 1. Write the C++ expression for the following mathematical statement a. y=(x-2)(x+3) b. min = a + b + c + d + e 5 (2 marks) 2. Given the values x=5, y=5 and c=3. Write a program to calculate the value of z and display the output of z z = xy % c + 10 / 2y + 5; (4 marks) 3. Based on the flowchart, find the values for a and b. Write a program to calculate the values and display the output (4 marks) start x=12, y=8,z=5 a=x*y-z b = (6*a/2+3-z)/2 print a,b end CONCLUSION _____________________________________________________________________________________________ _____________________________________________________________________________________________ _____________________________________________________________________________________________ ________________________________