Assignment#1 in OOP
Assignment#1 in OOP
PROGRAMMING
COURCE CODE#CSC241
ASSIGNMENT#1
SUBMITTED TO: SIR SHAFIQ AHMED
int main()
int number;
cin>>number;
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>
int main()
{
cout<<“Hello\nWorld!”<<endl;
system(“pause”);
return 0;
}
OBJECT ORIENTED PROGRAMMING
Output :
Q#3:
Show output:
Program:
#include<iostream>
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.
float a = 30.152;
char s = ‘a’;
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
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;
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>
int main()
Int double=0;
System(“pause”);
Return 0;
OBJECT ORIENTED PROGRAMMING
}
Output:
Q#12:
Convert miles into Kilometers
Program:
#include<iostream>
int main()
float miles;
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>
main()
int val1,val2;
OBJECT ORIENTED PROGRAMMING
cout<<"Enter a first value from keyboard: ";
cin>>val1;
cin>>val2;
if(val1>val2)
else if(val2>val1)
int sum=val1+val2;
int difference=val1-val2;
int product=val1*val2;
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>
main()
double val1,val2;
cin>>val1;
OBJECT ORIENTED PROGRAMMING
cout<<"Enter a second value from keyboard: ";
cin>>val2;
if(val1>val2)
else if(val2>val1)
double sum=val1+val2;
double difference=val1-val2;
double product=val1*val2;
system("pause");
return 0;
Difference:
Double type data accept both floating and 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