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

Assignment 1 (24bsit039)

The document contains a programming assignment for B.Sc. IT Semester II, focusing on basic object-oriented programming concepts. It includes various tasks such as printing 'Hello World', performing arithmetic operations, and handling user input for calculations. Each task is accompanied by C++ code examples and expected outputs.

Uploaded by

bnfx4498jf
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)
8 views

Assignment 1 (24bsit039)

The document contains a programming assignment for B.Sc. IT Semester II, focusing on basic object-oriented programming concepts. It includes various tasks such as printing 'Hello World', performing arithmetic operations, and handling user input for calculations. Each task is accompanied by C++ code examples and expected outputs.

Uploaded by

bnfx4498jf
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/ 14

ASSIGNMENT – 1

B.SC. IT Semester – II

CTUC103 – Introduction to Object Oriented Programming

Student id – 24BSIT018

1. Write a program to print “Hello World”


Code:
#include<iostream>
using namespace std;
int main()
{
cout<<“Hello World”;
return 0;
}
Output:

2. Write a program to display any number entered by the user.


Code:
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter a number : ";
cin>>n;
cout<<"the number : "<<n;
return 0;
}
Output:

3. Write a program add two numbers and display the sum.


Code:
#include<iostream>
using namespace std;
int main()
{
int no1,no2;
cout<<"Enter a number 1 : ";
cin>>no1;
cout<<"Enter a number 2 : ";
cin>>no2;
cout<<"\nNumber : "<<no1;
cout<<"\nNumber : "<<no2;
cout<<"\nsum : "<<no1+no2;

return 0;
}
Output:
4. Write a program to find the area of circle. (Formula: Area = PI * r * r )
Code:
#include<iostream>
using namespace std;
int main()
{
int r;
float area;
cout<<"Enter a radious : ";
cin>>r;
area=(22*r*r)/7;
cout<<"area of circle : "<<area;

return 0;
}
Output:
5. Write a program to calculate simple interest. (Formula: SI = (P * R * N)
100)
Code:
#include<iostream>
using namespace std;
int main()
{
int p,r,n,si;
cout<<"Enter a principal : ";
cin>>p;
cout<<"Enter a rate of interest : ";
cin>>r;
cout<<"Enter a rate of time : ";
cin>>n;
si=(p*r*n)/100;
cout<<"simple interest : "<<si;
return 0;
}
Output:

6. Write a program to swap two values.


Code:
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter a two number : ";
cin>>a>>b;
swap(a,b);

cout<<"\n after swapping : ";


cout<<"\n value of a : "<<a;
cout<<"\n value of b : "<<b;
return 0;
}
Output:

7. Write a program to input a Student_Name, Branch, Semester, CGPA, and


Age, then display the details.
Code:
#include<iostream>
using namespace std;
int main()
{
int age,sem;
char s_name[20],branch[10];
float cgpa;

cout<<"Enter student name : ";


cin>>s_name;
cout<<"Enter branch : ";
cin>>branch;
cout<<"Enter semester : ";
cin>>sem;
cout<<"Enter student cgpa : ";
cin>>cgpa;
cout<<"Enter student age : ";
cin>>age;

cout<<"\nstudent name : "<<s_name;


cout<<"\nstudent branch : "<<branch;
cout<<"\nstudent semester : "<<sem;
cout<<"\nstudent cgpa : "<<cgpa;
cout<<"\nstudent age : "<<age;

return 0;
}
Output:

8. Write a program to perform addition, subtraction, multiplication, and


division of two integers and display the results.
Code:
#include<iostream>
using namespace std;
int main()
{
int no1,no2;

cout<<"Enter no1 and no2 : ";


cin>>no1>>no2;
cout<<"\n addition : "<<no1+no2;
cout<<"\n subtraction : "<<no1-no2;
cout<<"\n multiplication : "<<no1*no2;
cout<<"\n division : "<<(float)no1/no2;
return 0;
}
Output:

9. Write a program to check whether the entered number is even or odd


using a user-defined function.
Code:
#include<iostream>
using namespace std;
void evenodd(int n)
{
if(n%2==0)
{
cout<<"even number : "<<n;
}
else
{
cout<<"\nodd number : "<<n;
}
}
int main()
{
int no;

cout<<"Enter a number : ";


cin>>no;
evenodd(no);
return 0;
}
Output:

10. Write a program to find the maximum between two numbers.


Code:
#include<iostream>
using namespace std;
int main()
{
int no1,no2;

cout<<"Enter a no1 and no2 : ";


cin>>no1>>no2;
cout<<"\nmaximum number : "<<max(no1,no2);

return 0;
}
Output:

11. Write a program to find the maximum among three numbers.


Code:
#include<iostream>
using namespace std;
int main()
{
int no1,no2,no3;

cout<<"Enter a no1 and no2 and no3 : ";


cin>>no1>>no2>>no3;
if(no1>no2 && no1>no3)
{
cout<<"\nmaximum number "<<no1;
}
else if(no2>no1 && no2>no3)
{
cout<<"\nmaximum number "<<no2;
}
else
{
cout<<"\nmaximum number "<<no3;
}
return 0;
}
Output:

12. Write a program to input five numbers into an array and display them.
Code:
#include<iostream>
using namespace std;
int main()
{
int n[5],i;
for(int i=0; i<5; i++)
{
cin>>n[i];
}
for(int i=0; i<5; i++)
{
cout<<"\n numbers : "<<n[i];
}
return 0;
}
Output:
13. Write a program to input five subject marks into an array, then display
the total marks and average marks.
Code:
#include<iostream>
using namespace std;
int main()
{
int marks[5],i,total=0;
float avg;

for(int i=0; i<5; i++)


{
cout<<"Enter marks of five subject : ";
cin>>marks[i];
total=total+marks[i];
}
avg=(float)total/5;
cout<< "\ntotal marks : "<<total;
cout<< "\navarage marks : "<<avg;

return 0;
}
Output:
14. Write a program to find the maximum number in an array.
Code:
#include <iostream>
using namespace std;
int main()
{
int n,x[n],i;
cout << "Enter the numbers: ";
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x[i];
}
int max = x[0];
for (int i = 1; i < n; i++)
{
if (x[i] > max)
{
max = x[i];
}
}
cout << "The maximum number in the array is: " << max;

return 0;
}
Output:

15. Write a menu-driven program using a switch case to input two numbers
from the user and perform all the basic arithmetic operations.
Code:
#include <iostream>
using namespace std;
int main()
{
int a,b,choice;
float res;
cout<<"enter the first number : ";
cin>>a;
cout<<"enter the second number : ";
cin>>b;
cout<<"enter the choice from below \n1 for addition \n2 for
subtraction \n3 for multiplication \n4division ";
cout<<"\nenter the choice : ";
cin>>choice;
switch(choice)
{
case 1:res=a+b;
cout<<"\naddition = "<<res;
case 2:res=a-b;
cout<<"\nsubtraction = "<<res;
case 3:res=a*b;
cout<<"\nmultiplication = "<<res;
case 4:res=a/b;
cout<<"\ndivision = "<<res;
default : cout<<"\ninvaidoparater";
}

return 0;
}
Output:

You might also like