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

OOP Assignment 1

The document contains code snippets from multiple C++ programs. Program 1 adds two integers and prints the sum. Program 2 checks if a number is even or odd. Program 3 prints the day of the week corresponding to a number input by the user using a switch statement. Program 4 prints numbers from 1 to 10 using a for loop. The remaining snippets contain additional C++ programs demonstrating concepts like nested for loops, swapping variables, finding the greatest of three numbers, and converting days to years, months and days. The document also provides brief explanations of object oriented programming and the differences between C and C++ languages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

OOP Assignment 1

The document contains code snippets from multiple C++ programs. Program 1 adds two integers and prints the sum. Program 2 checks if a number is even or odd. Program 3 prints the day of the week corresponding to a number input by the user using a switch statement. Program 4 prints numbers from 1 to 10 using a for loop. The remaining snippets contain additional C++ programs demonstrating concepts like nested for loops, swapping variables, finding the greatest of three numbers, and converting days to years, months and days. The document also provides brief explanations of object oriented programming and the differences between C and C++ languages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Program-2//

/*#include <iostream>
using namespace std;

int main()
{
int a, b, sum=0;
cout << "Enter two integers: ";
cin >> a >> b;
sum = a + b;
cout << a << " + " << b << " = " << sum;

return 0;
}
*/
//Program-3//
/*#include<iostream>
using namespace std;
int main()
{
int a;
cout << "Enter the number : ";
cin >> a;
if (a % 2 == 0)
cout << a << " is an even integer ";
else
cout << a << " is an odd integer ";

return 0;
}
*/
//Program-4//
/*#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n;
cout<<"Enter number for day: ";
cin>>n;

switch(n)
{
case 1: cout<<"Sunday"; break;
case 2:
cout<<"Monday";
break;

case 3:
cout<<"Tuesday";
break;

case 4:
cout<<"Wednesday";
break;

case 5:
cout<<"Thursday";
break;

case 6:
cout<<"Friday";
break;

case 7:
cout<<"Saturday";
break;

default:
cout<<"Invalid number!";
break;
}
return 0;
}
*/
//Program 5//
/*#include <iostream>
int main() {
int input;
for (int input = 1; input <= 10; input++) {
std::cout << "\n" << input;
}
}
*/
/*#include <iostream>
using namespace std;
int main(){
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
count<<"*";
}
count<<"\n";
return(0);
}
*/
//TASK-2//
/*#include <iostream>
using namespace std;
int main()
{
int a=15, b=55;
cout<<"Before swap a= "<<a<<" b= "<<b;
a=a*b;
b=a/b;
a=a/b;
cout<<"After swap a= "<<a<<" b= "<<b;
return 0;
}
*/
/*#include <iostream>
using namespace std;

int main()
{
int a,b,c,greatest;
cout<<"Enter three numbers : ";
cin>>a>>b>>c;
greatest=(a>b&&a>c)?a:(b>c)?b : c;
cout<<"Greatest number is "<<greatest;

return 0;
}
*/
/*#include<iostream>
using namespace std;

int main()
{
int days,y,m,d;
cout<<"Enter no. of days : ";
cin>>days;
y=days/365;
days=days%365;
m=days/30;
d=days%30;
cout<<"Years : "<<y<<"\nMonths : "<<m<<"\nDays : "<<d;

return 0;
}
*/
//Object Oriented programming (OOP) is a programming paradigm that relies on the concept of
classes and objects. It is used to structure a software program into simple, reusable pieces of
code blueprints (usually called classes), which are used to create individual instances of
objects.//
//The main difference between both these languages is C is a procedural programming
language and does not support classes and objects, while C++ is a combination of both
procedural and object-oriented programming languages.//

You might also like