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

oops lab1

The document contains three C++ programs: the first prints 'Hello World', the second creates and adds two 2D arrays, and the third demonstrates function overloading to sum different types of arguments. Each program includes code snippets and descriptions of their functionality. The outputs of the programs are also implied but not explicitly stated.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

oops lab1

The document contains three C++ programs: the first prints 'Hello World', the second creates and adds two 2D arrays, and the third demonstrates function overloading to sum different types of arguments. Each program includes code snippets and descriptions of their functionality. The outputs of the programs are also implied but not explicitly stated.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. write a c++ program to print Hello World.

#include <bits/stdc++.h>
using namespace std;
int main() {

std::cout << "Hello World";

return 0;
}

2. Write a c++ program to create a 2D array and addition of column and row separately.

CODE:-

#include <bits/stdc++.h>
using namespace std;

int main(){
int m,n;
cin>>m>>n;
int arr1[m][n], arr2[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr1[i][j];
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr2[i][j];
}
}
int arr_r[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
arr_r[i][j]=arr1[i][j]+arr2[i][j];
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cout<<arr_r[i][j]<<" ";
}
cout<<endl;
}
return 0;
}

OUTPUT:-

3. Write a c++ program for Passing arguments with help of function overloading-return the sum of 2
elements and output in main—return sum of 2 arguments-

a. both floating point arguments

b. both int arguments

c. one int and floating point arguments, return floating point

d. one int and floating point arguments, return int

CODE:-

#include <bits/stdc++.h>
using namespace std;

int add(int a,int b){


return a+b;
}
float add(int a, float b){
return a+b;
}
float add(float a, int b){
return a+b;
}
float add(float a,float b){
return a+b;
}

int main(){
int a=1,b=2;float a_f=1.1,b_f=2.1;
int s1=add(a,b);
cout<<"int 1 + int 2 = "<<s1<<endl;
float s2=add(a,b_f);
cout<<"int 1 + float 2.1 = "<<s2<<endl;
float s3=add(a_f,b);
cout<<"float 1.1 + int 2 = "<<s3<<endl;
float s4=add(a_f,b_f);
cout<<"float 1.1 + float 2.1 = "<<s4<<endl;
return 0;
}

OUTPUT:-

You might also like