programming
programming
Group assignment
0867/16
0870/16
0933/16
1373/16
0948/16
Submission date:-
January 12,2025
Bilew Alemu
display them.
switch statement.
10. Write a function to calculate the factorial of a number and
pass-by-reference.
integers.
area.
constructor.
23. Write a program to create a class Car and demonstrate
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 ;
int main() {
double pricePerItem;
int quantity;
double totalCost;
cout << "The total cost is: " << totalCost << endl;
return 0;
}
5, #include <iostream>
using namespace std;
int main() {
int number;
if (number > 0) {
cout << "The number is positive." << endl;
} else if (number < 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;
return 0;
}
7, #include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number to display its multiplication table: ";
cin >> num;
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;
}
int factorial(int n) {
if (n <= 1) {
return 1;
int main() {
int num;
cout << "The factorial of " << num << " is: " << factorial(num) <<
endl;
return 0;
}
11, #include <iostream>
int temp = a;
a = b;
b = temp;
int main() {
int x = 5, y = 10;
cout << "Before swap: x = " << x << ", y = " << y << endl;
swap(x, y);
cout << "After swap: x = " << x << ", y = " << y << endl;
return 0;
}
12, #include <iostream>
int temp = a;
a = b;
b = temp;
int main() {
int x = 5, y = 10;
cout << "Before swap: x = " << x << ", y = " << y << endl;
swap(x, y);
cout << "After swap: x = " << x << ", y = " << y << endl;
return 0;
largest = arr[i];
return largest;
int main() {
cout << "The largest element is: " << findLargest(arr, size) <<
endl;
return 0;
}
int count = 0;
while (*str) {
char ch = tolower(*str);
count++;
str++;
return count;
int main() {
cout << "The number of vowels is: " << countVowels(str) << endl;
return 0;
*a = *b;
*b = temp;
int main() {
int x = 5, y = 10;
cout << "Before swapping: x = " << x << ", y = " << y << endl;
swap(&x, &y);
cout << "After swapping: x = " << x << ", y = " << y << endl;
return 0;
}
int main() {
int n;
cin >> n;
int sum = 0;
sum += arr[i];
cout << "Sum of array elements: " << sum << endl;
delete[ ] arr;
return 0;
struct Student {
string name;
int age;
float marks;
};
int main() {
int n;
cin >> n;
Student* students = new Student[n];
cout << "Enter details of student " << i + 1 << ":" << endl;
cout << "Name: " << students[i].name << ", Age: " <<
delete[] students;
return 0;
class Book {
private:
string title;
string author;
float price;
public:
title = t;
author = a;
price = p;
void displayDetails() {
};
int main() {
Book book;
float price;
getline(cin, title);
getline(cin, author);
book.displayDetails();
return 0;
class Rectangle {
private:
float length;
float breadth;
public:
length = l;
breadth = b;
float calculateArea() {
void displayDetails() {
cout << "Length: " << length << ", Breadth: " << breadth <<
endl;
};
int main() {
Rectangle rect;
rect.setDimensions(length, breadth);
rect.displayDetails();
return 0;
class Circle {
private:
double radius;
public:
Circle(double r) : radius(r) {
cout << "Constructor called: Circle created with radius = " <<
Circle() {
cout << "Destructor called: Circle with radius " << radius << "
}
double getArea() const {
};
int main() {
Circle circle1(5.0);
cout << "Area of the circle: " << circle1.getArea() << endl;
return 0;
class Box {
private:
public:
width(w), height(h) {}
cout << "Length: " << length << ", Width: " << width << ",
length = l;
width = w;
height = h;
};
int main() {
double l, w, h;
cin >> l;
cin >> w;
cin >> h;
return 0;
class Student {
private:
string name;
int rollNumber;
public:
cout << "Name: " << name << ", Roll Number: " << rollNumber
<< endl;
};
int main() {
Student student;
student.displayDetails();
return 0;
class Car {
private:
string brand;
int year;
public:
cout << "Brand: " << brand << ", Year: " << year << endl;
};
int main() {
carPtr->displayDetails();
delete carPtr;
return 0;
struct Employee {
string name;
int id;
double salary;
cout << "Name: " << name << ", ID: " << id << ", Salary: $" <<
};
int main() {
emp.displayDetails();
return 0;
union Data {
int intValue;
float floatValue;
char charValue;
};
int main() {
Data data;
data.intValue = 42;
data.displayInt();
data.floatValue = 3.14f;
data.displayFloat();
data.charValue = 'A';
data.displayChar();
return 0;