oops lab1
oops lab1
#include <bits/stdc++.h>
using namespace std;
int main() {
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-
CODE:-
#include <bits/stdc++.h>
using namespace std;
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:-