0% found this document useful (0 votes)
5 views8 pages

Practical No 1-1

The document contains practical exercises for a C++ programming course, including the creation of a simple calculator, conversion of seconds into hours, minutes, and seconds, and calculations for the volume of a square, cone, and rectangle. Each section includes the program code and expected outputs. The exercises aim to enhance understanding of object-oriented programming concepts using C++.

Uploaded by

Ahlam Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Practical No 1-1

The document contains practical exercises for a C++ programming course, including the creation of a simple calculator, conversion of seconds into hours, minutes, and seconds, and calculations for the volume of a square, cone, and rectangle. Each section includes the program code and expected outputs. The exercises aim to enhance understanding of object-oriented programming concepts using C++.

Uploaded by

Ahlam Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Practical no 1

NAME: Yash Amit Gadade Roll no:28 Class:FYIT

Subject:Object oriented programming with c++ Date:

Aim:(A) Write a C++ program to create a simple calculator.

Program:

#include<iostream>

using namespace std;

int main()

char op;

float num1,num2;

cout<<"Enter operator:+,-,/,*=";

cin>>op;

cout<<"Enter two operands:";

cin>>num1>>num2;

switch(op)

case'+':

cout<<num1<<"+"<<num2<<"="<<num1+num2;

break;

case'-':

cout<< num1<<"-"<<num2<<"="<<num1-num2;
break;

case'*':

cout<<num1<<"*"<<num2<<"="<<num1*num2;

break;

case'/':

cout<<num1<<"/"<<num2<<"="<<num1/num2;

break;

default:

//if the opertor is other than +, -,*or/,error message is shown

cout<<"Error! operator is not correct";

break;

return 0;

Output:
(B) write a C++ program to covert seconds into hours,minutes and seconds.

Program:

#include<iostream>

#include<conio.h>

using namespace std;

int main()

int h,m,s,ts;

cout<<"Enter total seconds:";

cin>>ts;

h=ts/3600;

m=(ts%3600)/60;

s=(ts%3600)%60;

cout<<"Hours="<<h<<endl;

cout<<"minutes="<<m<<endl;

cout<<"second="<<s;

return 0;

Output:
(C) Write a C++ program to find the volume of a square,cone,and rectangle.

Square:

/*program to calculate the area of square*/

Code: #include <iostream>

using namespace std;

int main()

//function main begins program execution

int square_area, square_side;

cout << "Enter the side of square:";

cin >> square_side;

square_area = square_side * square_side;

cout << "Area of Square: " << square_area << endl;

return 0;

}
Output:

Cone:

Code:

#include <iostream>

#include <string>

using namespace std;

int main ()

const float pi = 3.14159;

float R, H, V;

cout << "Input Cone's radius: ";

cin >> R;

cout << "Input Cone's height: ";


cin >> H;

// Cone's volume.

V = (1.0/0.3)*pi*(R*R)*H;

cout << "The volume of the cone is: " << V ;

return 0;

Output:

Rectangle:

Code:

#include<iostream>

#include<math.h>

using namespace std;

static double pi=3.1415926535;


int main()

double side1,side2,side3,Ans;

cout<<"Enter Side 1 = ";

cin>>side1;

cout<<"Enter Side 2 = ";

cin>>side2;

cout<<"Enter Side 3 = ";

cin>>side3;

Ans=side1*side2*side3;

cout<<"Volume of Rectangular Prism = "<<Ans<<endl;

system("pause");

}
Output:

You might also like