0% found this document useful (0 votes)
7 views7 pages

Lecture 5 - Input Statements

The document outlines the process of getting user input in C++ using the standard input stream and the extraction operator. It includes a class exercise to write a simple program that computes the sum of two integers, as well as additional exercises for calculating profit from vehicle sales and the area and perimeter of a right-angled triangle. The document also provides a sample C++ code for user input and computation.

Uploaded by

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

Lecture 5 - Input Statements

The document outlines the process of getting user input in C++ using the standard input stream and the extraction operator. It includes a class exercise to write a simple program that computes the sum of two integers, as well as additional exercises for calculating profit from vehicle sales and the area and perimeter of a right-angled triangle. The document also provides a sample C++ code for user input and computation.

Uploaded by

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

Input Statements

|
Outline

• Get input from user

04/27/202
5
Lecture 3: Escape Sequences & Variables |
cin>>

• The standard input stream


• This name belongs to the namespace std

04/27/202
5
Lecture 3: Escape Sequences & Variables |
>>

• Referred to as the extraction operator


• The operator is applied to an input stream

04/27/202
5
Lecture 3: Escape Sequences & Variables |
Class Exercise

• Write a simple C++ program that allows a


user to input any two integers and the
program computes their sum.

• What variables do we need?


(3 integers, num1, num2, sum)
• How do we get the input?

04/27/202
5
Lecture 3: Escape Sequences & Variables |
#include<iostream>

using namespace std;

int main()
{
Always
int num1, num2; prompt
double sum; the user
to enter
cout<<"Enter any two integers\n";
the
cin>>num1; informati
cin>>num2; on you
want.
sum=num1+num2;
cout<<“Sum is:"<<sum<<"\n";
system("pause");
return 0;
}

04/27/202
5
Lecture 3: Escape Sequences & Variables |
Class Exercise

• Write a program that computes the profit


made for selling a motor vehicle. The
program should allow a user to input the
buying price and selling price and then
compute the profit.
• Write a program to calculate the area and
perimeter of a right angled triangle. The
program should allow a user to enter the
base, height and hypotenuse of a triangle
and display the area and perimeter to the
end user.
04/27/202
5
Lecture 3: Escape Sequences & Variables |

You might also like