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

c++

The document contains multiple C++ programs demonstrating various functionalities such as calculating the area of a circle, performing arithmetic operations, checking number positivity, finding the largest of three numbers, displaying multiplication tables, and implementing a factorial function. It also includes a class definition for a Box with methods for setting and displaying dimensions. Each program prompts the user for input and displays the corresponding output.

Uploaded by

lielinazena.1
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

c++

The document contains multiple C++ programs demonstrating various functionalities such as calculating the area of a circle, performing arithmetic operations, checking number positivity, finding the largest of three numbers, displaying multiplication tables, and implementing a factorial function. It also includes a class definition for a Box with methods for setting and displaying dimensions. Each program prompts the user for input and displays the corresponding output.

Uploaded by

lielinazena.1
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1, #include <iostream>

using namespace std;


int main ()
{
float pi=3.14;
float radius, area ;
cout<< "enter the radius of the circle"<<endl;
cin>>radius;
area=pi* radius* radius;
cout<<"area of the circle is "<< area<<endl;
return 0;
}
2, #include <iostream>
using namespace std;
int main() {
float a,b ;

cout<<"enter two number"<<endl;


cin>> a>>b;
cout<<"the multiplication of two numbers is "<< a*b <<endl;
cout<< "the addition of two numbers is "<< a+b << endl;
cout<< "the substractiom of two number is "<< a-b<< endl;
cout<< "the division of two numbers is "<< a/b<< endl;
return 0;
}
3, #include <iostream>
using namespace std;
int main() {
string name;
int age;
cout<< "enter your user name "<<endl;
cin>>name;
cout<< "enter your age "<<endl;
cin>>age;
cout<< " hi " << name << " you are " << age <<" years old";
return 0;
}
4,
5. #include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
if (num > 0) {
cout << "The number is positive." << endl;
} else if (num < 0) {
cout << "The number is negative." << endl;
} else {
cout << "The number is zero." << endl;
}

return 0;
}
6.#include <iostream>
using namespace std;

int main() {
int a, b, c;
cout << "Enter three numbers: ";
cin >> a >> b >> c;

int largest = (a > b && a > c) ? a : (b > c) ? b : c;


cout << "The largest number is: " << largest << endl;

return 0;
}
7.#include <iostream>
using namespace std;

int main() {
int num;
cout << "Enter a number to display its multiplication table: ";
cin >> num;

for (int i = 1; i <= 10; i++) {


cout << num << " * " << i << " = " << num * i << endl;
}

return 0;
}
8.#include <iostream>
using namespace std;

int main() {
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
continue; // Skip even numbers
}
cout << i << " ";
}
cout << endl;

return 0;
}
9.#include <iostream>
using namespace std;

int main() {
int day;
cout << "Enter a number (1-7) to get the day of the week: ";
cin >> day;

switch (day) {
case 1:
cout << "Monday" << endl;
break;
case 2:
cout << "Tuesday" << endl;
break;
case 3:
cout << "Wednesday" << endl;
break;
case 4:
cout << "Thursday" << endl;
break;
case 5:
cout << "Friday" << endl;
break;
case 6:
cout << "Saturday" << endl;
break;
case 7:
cout << "Sunday" << endl;
break;
default:
cout << "Invalid input! Please enter a number between 1 and 7." << endl;
break;
}

return 0;
}
10.#include <iostream>
using namespace std;

int factorial(int n) {
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
}

int main() {
int num;
cout << "Enter a number to calculate its factorial: ";
cin >> num;

cout << "The factorial of " << num << " is: " << factorial(num) << endl;

return 0;
}
21, #include <iostream>
using namespace std;

class Box {
private:
double length, width, height;

public:
// Default and Parameterized Constructor
Box(double l = 0, double w = 0, double h = 0) : length(l), width(w), height(h) {}

// Copy Constructor
Box(const Box &b) = default;

// Function to display dimensions


void displayDimensions() const {
cout << "Length: " << length << ", Width: " << width << ", Height: " << height << endl;
}

// Function to set dimensions


void setDimensions(double l, double w, double h) {
length = l;
width = w;
height = h;
}
};

int main() {
double l, w, h;

// Prompting user for dimensions


cout << "Enter length: ";
cin >> l;
cout << "Enter width: ";
cin >> w;
cout << "Enter height: ";
cin >> h;

// Creating an object using user input


Box userBox(l, w, h);

// Displaying the dimensions of the box created with user input


userBox.displayDimensions();

return 0;
}

You might also like