1-Amaliyot ishi.
1-topshiriq.
USTOZ (ismi, yoshi, maktab, sinf)
|
Sinf = 9
|
#include
using namespace std;
class Teacher {
public:
string name;
int age;
string school;
int grade;
void teach() {
cout << name << " is teaching grade " << grade << " at " << school << "." << endl;
}
};
int main() {
Teacher myTeacher;
myTeacher.name = "Mrs. Smith";
myTeacher.age = 35;
myTeacher.school = "Example High School";
myTeacher.grade = 9;
myTeacher.teach();
return 0;
}
2-topshiriq.
Modemlar sinfini yarating. Unda kamida 5 ta maydon va ularni ekranga chiqaruvchi, qayta ishlovchi metodlarni yarating.
#include
using namespace std;
class Modems {
private:
double price;
int speed;
string manufacturer;
string modelNumber;
bool wifi;
public:
Modems(double p, int s, string m, string mn, bool w) {
price = p;
speed = s;
manufacturer = m;
modelNumber = mn;
wifi = w;
}
double getPrice() {
return price;
}
int getSpeed() {
return speed;
}
string getManufacturer() {
return manufacturer;
}
string getModelNumber() {
return modelNumber;
}
bool hasWifi() {
return wifi;
}
void displayInfo() {
cout << "Manufacturer: " << manufacturer << endl;
cout << "Model Number: " << modelNumber << endl;
cout << "Price: $" << price << endl;
cout << "Speed: " << speed << " Mbps" << endl;
if (wifi) {
cout << "Wifi enabled." << endl;
} else {
cout << "Wifi not enabled." << endl;
}
}
void processInfo() {
if (price > 100) {
cout << "This modem is expensive." << endl;
} else {
cout << "This modem is affordable." << endl;
}
if (speed >= 1000) {
cout << "This modem has high speed." << endl;
} else {
cout << "This modem has average speed." << endl;
}
}
};
int main() {
Modems myModem(99.99, 500, "Netgear", "CM500", true);
myModem.displayInfo();
myModem.processInfo();
return 0;
}
2-amaliyot ishi.
1-topshiriq.
Vector ni 2 ga va 5 ga bo`linadigan elementlarini ko`paytmasini sinusi tоpilsin
#include
int main() {
double x = 2.0;
double y = 5.0;
double z = 3.0;
double magnitude = sqrt(x*x + y*y + z*z);
double sine = y / magnitude;
return 0;
}
2-topshiriq.
Vektorning manfiy elementlari kvadratlarining yig’indisi hisoblansin.
#include
#include
int main() {
std::vector v = {1, -2, 3, -4, 5};
int sum_squares = 0;
for (auto i : v) {
if (i < 0) {
sum_squares += i * i;
}
}
std::cout << "The sum of the squares of the negative elements is " << sum_squares << std::endl;
return 0;
}
3-topshiriq.
Vektorni juft qiymatli elementlarini o`rtacha qiymatidan hisoblansin
#include
#include
int main() {
std::vector input_vector = {3, 5, 2, 10, 6, 8};
std::vector output_vector;
int sum = 0;
int count = 0;
for (auto element : input_vector) {
if (element % 2 == 0) {
sum += element;
count += 1;
}
}
if (count > 0) { // avoid zero division error
int average = sum / count;
for (auto element : input_vector) {
if (element % 2 == 0) {
output_vector.push_back(average);
} else {
output_vector.push_back(element);
}
}
} else {
// no even-valued elements found, the output vector is the same as the input
output_vector = input_vector;
}
std::cout << "Input vector: ";
for (auto element : input_vector) {
std::cout << element << " ";
}
std::cout << std::endl;
std::cout << "Output vector: ";
for (auto element : output_vector) {
std::cout << element << " ";
}
std::cout << std::endl;
return 0;
}
3-amaliyot ishi.
Ro’yxat(list) berilgan . Uning eng katta elementi topilsin
#include
#include
#include
int main() {
std::vector my_list = {5, 2, 8, 2, 14, 7};
int largest_element = *std::max_element(my_list.begin(), my_list.end());
std::cout << "The largest element in the list is: " << largest_element << std::endl;
}
4-amaliyot ishi.
1-topshiriq.
X to‘plam berilgan. X to‘plamdagi manfiy qiymatlarni Z to‘plamga ko‘chirib yozing.
#include
#include
int main() {
std::set X = {-5, 3, -1, 7, -10, 4};
std::set Z;
for (auto x : X) {
if (x < 0) {
Z.insert(x);
}
}
std::cout << "Set X: ";
for (auto x : X) {
std::cout << x << " ";
}
std::cout << "\nSet Z: ";
for (auto z : Z) {
std::cout << z << " ";
}
std::cout << std::endl;
return 0;
}
2-topshiriq.
Berilgan string turidagi to’plamda kata harfdan va kichik harfdan boshlanuvchi elementlari soni aniqlovchi hamda ularni ekranga chiqaruvchi dastur tuzing.
#include
#include
#include
#include
int main()
{
std::string input_string;
std::cout << "Enter a string to analyze: ";
std::getline(std::cin, input_string);
std::set uppercase_letters;
std::set lowercase_letters;
for (char c : input_string)
{
if (std::isupper(c))
{
uppercase_letters.insert(c);
}
else if (std::islower(c))
{
lowercase_letters.insert(c);
}
}
std::cout << "Number of uppercase letters: " << uppercase_letters.size() << std::endl;
std::cout << "Number of lowercase letters: " << lowercase_letters.size() << std::endl;
return 0;
}
Dostları ilə paylaş: |