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

Assignment#1 in OOP

I am student in COMSATS University Islamabad(Sahiwal campus). And I have done my protect in Java. That's way I help that website. Thanks .........

Uploaded by

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

Assignment#1 in OOP

I am student in COMSATS University Islamabad(Sahiwal campus). And I have done my protect in Java. That's way I help that website. Thanks .........

Uploaded by

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

OBJECT ORIENTED

PROGRAMMING
COURCE CODE#CSC241

ASSIGNMENT#1
SUBMITTED TO: SIR SHAFIQ AHMED

SUBMITTED BY: NADEEM AHMED


Roll No# SP19-MCS-016
OBJECT ORIENTED PROGRAMMING
Q#1:
 Receive input from user
Program:
#include<iostream>

using namespace std;

int main()

int number;

cout<<"Enter a number from keyboard: ";

cin>>number;

cout<<"You enter: "<<number<<endl;

system("pause");

return 0;

Output:
OBJECT ORIENTED PROGRAMMING

Q#2
Purpose of “/N”
This is called Escape Sequence. In programming language, it’s equivalent to pressing
Enter and starting a new to start writing in any word processor. Now we check it by a
program:

Program:
#include <iostream>

using namespace std;

int main()
{
cout<<“Hello\nWorld!”<<endl;

system(“pause”);

return 0;
}
OBJECT ORIENTED PROGRAMMING
Output :

Q#3:
Show output:
Program:
#include<iostream>

using namespace std;

main()

string first_name="NADEEM";

cout<<"Hello,"<<first_name<<"!\n";

system("pause");

return 0;}
OBJECT ORIENTED PROGRAMMING
Output:

Q#4:
Literals:
“Constants refer to fixed values that the program may not alter and they are called literals.”

Q#5:
 Kinds of Literals:
“Literals are the values that are fixed during execution of the
program.” There are five kinds of literals in C++.
1) Integer Literal
2) Floating Point Literal
3) Boolean Literal.
4) Character Literal.
5) String Literal.

1) Integer Literal: These are numbers without fraction part.


For Example :
OBJECT ORIENTED PROGRAMMING
Int a = 10;
2) Floating Point Literals: These are decimal numbers also
having their fractional part.
For Example :

float a = 30.152;

3) Boolean Literals: These are values having only two values


i.e. True and False.
For Example :

bool var = true;

4) Character Literals: These are values enclosed in single


quotes.
For Example :

char s = ‘a’;

5) String Literals: These are same as character literals but


enclosed in double quotes. Also they are the array of characters.
For Example :

char s[] = “hello”;

Q#6:
Ans:
Space, tabs does not effect on our program.

Q#7:
 Data types and its size in C++
Data types specify how we enter data into our programs and what type of data we enter.
C++ language has some predefined set of data types to handle various kinds of data
that we can use in our program. These data types have different storage capacities.

These are fundamental data types in C++ namely integer (int), floating
point(float), character(char) and double.
OBJECT ORIENTED PROGRAMMING

Type Size(bytes) Range

int 2 -32,768 to 32767

Float 4 3.4E-38 to 3.4E+38

Double 8 1.7E-308 to 1.7E+308

Char 1 -128 to 127

Q#8:
Memory used for small entities:
In memory byte is used to store small
sized memory like:
Int data type used “4bytes” in memory.

Q#9:
 Assignment operator(=)
The symbol (=) is called assignment operator. It is used to store a value or result of an
expression in a variable.

For Example:

X=2;
OBJECT ORIENTED PROGRAMMING
Y=3.5;

 Equal to operator (==)


The symbol (==) is a relation operator that are used to compare two values or
expression. It means the result is true if both values are equal.IF

X=10;

Y=10;

X==Y; True

Q#10:
 Variable Initialization
“Assigning a value to a variable at the time of declaration is called variable
initialization.”
For Example:
Int x=5;
Float a=3.5; etc.

 Variable assignment:
“Specifying variable name and the type of data it can contain is known as variable
assignment.’’

Int x;

Char a; etc.

Q#11:
#include<iostream>

using namespace std;

int main()

Int double=0;

System(“pause”);

Return 0;
OBJECT ORIENTED PROGRAMMING
}

Output:

Q#12:
 Convert miles into Kilometers
Program:
#include<iostream>

using namespace std;

int main()

float miles;

cout<<"Enter a number of miles to convert into a kilometers: ";

cin>>miles;
OBJECT ORIENTED PROGRAMMING
cout<<"The converted value of "<<miles<<" miles is= "<<miles*1.609<<" kilometers"<<endl;

system("pause");

return 0;}

Output:

Q#13:
Show sum, difference, product, gratest &
smallest value
Program:
#include<iostream>

using namespace std;

main()

int val1,val2;
OBJECT ORIENTED PROGRAMMING
cout<<"Enter a first value from keyboard: ";

cin>>val1;

cout<<"Enter a second value from keyboard: ";

cin>>val2;

if(val1>val2)

cout<<val1<<" is largest.\n"<<val2<<" is smallest."<<endl;

else if(val2>val1)

cout<<val2<<" is largest.\n"<<val1<<" is smallest."<<endl;

int sum=val1+val2;

cout<<"Sum of two numbers is = "<<sum<<endl;

int difference=val1-val2;

cout<<"Difference of two numbers is = "<<difference<<endl;

int product=val1*val2;

cout<<"Product of two numbers is = "<<product<<endl;

system("pause");

return 0;

 Difference:
Int type data can only be store integer values.

Output:
OBJECT ORIENTED PROGRAMMING

Q#14:
Show sum difference product gratest &
smallest value
Program:
#include<iostream>

using namespace std;

main()

double val1,val2;

cout<<"Enter a first value from keyboard: ";

cin>>val1;
OBJECT ORIENTED PROGRAMMING
cout<<"Enter a second value from keyboard: ";

cin>>val2;

if(val1>val2)

cout<<val1<<" is largest.\n"<<val2<<" is smallest."<<endl;

else if(val2>val1)

cout<<val2<<" is largest.\n"<<val1<<" is smallest."<<endl;

double sum=val1+val2;

cout<<"Sum of two numbers is = "<<sum<<endl;

double difference=val1-val2;

cout<<"Difference of two numbers is = "<<difference<<endl;

double product=val1*val2;

cout<<"Product of two numbers is = "<<product<<endl;

system("pause");

return 0;

 Difference:
Double type data accept both floating and integer values.

But int type data can only be store integer values.

Output:
OBJECT ORIENTED PROGRAMMING

Q#15:
Check Even or Odd:
Program:
#include<iostream>
using namespace std;
main()
{
int num;
cout<<"Enter a number from keyboard: ";
cin>>num;
if(num%2==0)
cout<<num<<" is even number."<<endl;
else
cout<<num<<" is odd number."<<endl;

system("pause");
return 0;
}

Output:
OBJECT ORIENTED PROGRAMMING

Q#16:
Using assignment & increment operator
show the following
Program:
#include<iostream>
using namespace std;
main()
{
int a=10,n=10;
cout<<n<<endl;
a+=n;
cout<<a<<endl;
a--;
cout<<a<<endl;
system("pause");
return 0;
}
Output:
OBJECT ORIENTED PROGRAMMING

Q#17:
Show output
Program:
#include<iostream>
using namespace std;
main()
{
cout<<"Year Result\n";
cout<<"---------------\n";
cout<<"1990 135\n";
cout<<"1991 7290\n";
cout<<"1992 11300\n";
cout<<"1993 16200\n";
system("pause");
return 0;
}
Output:
OBJECT ORIENTED PROGRAMMING

You might also like