نصائح و استشارات برمجية
اشتي نشاط اله حاسبة. بإستخدام ال else_if ladder. بحيث أنه المستخدم يدخل أما اسم العملية أو رقم العملية ورقمين ويعمل له الجميع ويطلع له النتيجة. الطريقة اشتيها ب استخدام ال else_if ladder ممكن تجاوبوا لي ع هذا بشرط يكون معمول بكود
#include <iostream>
using namespace std;
int main() {
double num1, num2;
char operation;
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
cout << "Enter operation (+, -, *, /): ";
cin >> operation;
if (operation == '+' || operation == '1') {
cout << "Result: " << num1 + num2 << endl;
} else if (operation == '-' || operation == '2') {
cout << "Result: " << num1 - num2 << endl;
} else if (operation == '*' || operation == '3') {
cout << "Result: " << num1 * num2 << endl;
} else if (operation == '/' || operation == '4') {
if (num2 != 0) {
cout << "Result: " << num1 / num2 << endl;
} else {
cout << "Error: Division by zero is undefined." << endl;
}
} else {
cout << "Error: Invalid operation." << endl;
}
return 0;
}
using namespace std;
int main() {
double num1, num2;
char operation;
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
cout << "Enter operation (+, -, *, /): ";
cin >> operation;
if (operation == '+' || operation == '1') {
cout << "Result: " << num1 + num2 << endl;
} else if (operation == '-' || operation == '2') {
cout << "Result: " << num1 - num2 << endl;
} else if (operation == '*' || operation == '3') {
cout << "Result: " << num1 * num2 << endl;
} else if (operation == '/' || operation == '4') {
if (num2 != 0) {
cout << "Result: " << num1 / num2 << endl;
} else {
cout << "Error: Division by zero is undefined." << endl;
}
} else {
cout << "Error: Invalid operation." << endl;
}
return 0;
}
نصائح و استشارات برمجية
كود برمجي بلغة سي بلاس بلاس باستخدام For لعدد اولي
#include <iostream>
bool isPrime(int number) {
if (number <= 1) {
return false;
}
for (int i = 2; i <= number / 2; ++i) {
if (number % i == 0) {
return false;
}
}
return true;
}
int main() {
int n;
std::cout << "Enter the number of prime numbers you want to print: ";
std::cin >> n;
std::cout << "The first " << n << " prime numbers are: ";
for (int i = 2, count = 0; count < n; ++i) {
if (isPrime(i)) {
std::cout << i << " ";
++count;
}
}
return 0;
}
bool isPrime(int number) {
if (number <= 1) {
return false;
}
for (int i = 2; i <= number / 2; ++i) {
if (number % i == 0) {
return false;
}
}
return true;
}
int main() {
int n;
std::cout << "Enter the number of prime numbers you want to print: ";
std::cin >> n;
std::cout << "The first " << n << " prime numbers are: ";
for (int i = 2, count = 0; count < n; ++i) {
if (isPrime(i)) {
std::cout << i << " ";
++count;
}
}
return 0;
}
السلام عليكم ازيك حضرتك يا رب تكون بخير ممكن اعرف ليه بيطلعلي في price و payment صفر
#include <iostream>
using namespace std;
class Rectangle
{
private:
//telephone
string name;
float price;
string model;
string color;
float payment;
public:
void setName(string n)
{
name =n;
}
void setprice(float p)
{
price =p;
}
void setcolor(string c)
{
color =c;
}
void setpayment(float m)
{
payment =m;
}
void setmodel(string mod)
{
model =mod;
}
string getname()
{
return name;
}
float getprice()
{
return price;
}
string getcolor()
{
return color;
}
float getpayment()
{
return price/payment;
}
string getmodel()
{
return model;
}
void print()
{
cout<< "Name of phone:"<<name<<endl;
cout<<"price of phone:"<<price<<endl;
cout <<"color of phone:"<<color<<endl;
cout <<"Numbers of months to pay the phone:"<<payment<<endl;
cout <<"model of phone:"<<model<<endl;
}
};
int main()
{
Rectangle y;
y.setName("Iphone");
y.setcolor("Black");
y.setmodel("model is 2005");
y.print();
y.setprice(2000);
y.setpayment(2);
return 0;
}
using namespace std;
class Rectangle
{
private:
//telephone
string name;
float price;
string model;
string color;
float payment;
public:
void setName(string n)
{
name =n;
}
void setprice(float p)
{
price =p;
}
void setcolor(string c)
{
color =c;
}
void setpayment(float m)
{
payment =m;
}
void setmodel(string mod)
{
model =mod;
}
string getname()
{
return name;
}
float getprice()
{
return price;
}
string getcolor()
{
return color;
}
float getpayment()
{
return price/payment;
}
string getmodel()
{
return model;
}
void print()
{
cout<< "Name of phone:"<<name<<endl;
cout<<"price of phone:"<<price<<endl;
cout <<"color of phone:"<<color<<endl;
cout <<"Numbers of months to pay the phone:"<<payment<<endl;
cout <<"model of phone:"<<model<<endl;
}
};
int main()
{
Rectangle y;
y.setName("Iphone");
y.setcolor("Black");
y.setmodel("model is 2005");
y.print();
y.setprice(2000);
y.setpayment(2);
return 0;
}
نصائح و استشارات برمجية
السلام عليكم ازيك حضرتك يا رب تكون بخير ممكن اعرف ليه بيطلعلي في price و payment صفر
• و عليكم السلام و رحمة الله و بركاته
• لازم تخلي شرط في القسمة، انه لو payment لا تساوي صفر يبقى يرجعلك قيمة قسمتهم، لو بتساوي صفر خليه يرجعلك صفر، زي كدا ⬇️
#include <iostream>
using namespace std;
class Rectangle
{
private:
string name;
float price;
string model;
string color;
float payment;
public:
void setName(string n)
{
name = n;
}
void setprice(float p)
{
price = p;
}
void setcolor(string c)
{
color = c;
}
void setpayment(float m)
{
payment = m;
}
void setmodel(string mod)
{
model = mod;
}
string getname()
{
return name;
}
float getprice()
{
return price;
}
string getcolor()
{
return color;
}
float getpayment()
{
if (payment != 0)
return price / payment;
else
return 0;
}
string getmodel()
{
return model;
}
void print()
{
cout << "Name of phone:" << name << endl;
cout << "Price of phone:" << price << endl;
cout << "Color of phone:" << color << endl;
cout << "Numbers of months to pay the phone:" << payment << endl;
cout << "Model of phone:" << model << endl;
}
};
int main()
{
Rectangle y;
y.setName("Iphone");
y.setcolor("Black");
y.setmodel("model is 2005");
y.setprice(2000);
y.setpayment(2);
y.print();
return 0;
}
• لازم تخلي شرط في القسمة، انه لو payment لا تساوي صفر يبقى يرجعلك قيمة قسمتهم، لو بتساوي صفر خليه يرجعلك صفر، زي كدا ⬇️
#include <iostream>
using namespace std;
class Rectangle
{
private:
string name;
float price;
string model;
string color;
float payment;
public:
void setName(string n)
{
name = n;
}
void setprice(float p)
{
price = p;
}
void setcolor(string c)
{
color = c;
}
void setpayment(float m)
{
payment = m;
}
void setmodel(string mod)
{
model = mod;
}
string getname()
{
return name;
}
float getprice()
{
return price;
}
string getcolor()
{
return color;
}
float getpayment()
{
if (payment != 0)
return price / payment;
else
return 0;
}
string getmodel()
{
return model;
}
void print()
{
cout << "Name of phone:" << name << endl;
cout << "Price of phone:" << price << endl;
cout << "Color of phone:" << color << endl;
cout << "Numbers of months to pay the phone:" << payment << endl;
cout << "Model of phone:" << model << endl;
}
};
int main()
{
Rectangle y;
y.setName("Iphone");
y.setcolor("Black");
y.setmodel("model is 2005");
y.setprice(2000);
y.setpayment(2);
y.print();
return 0;
}
ياجماعه اذا ابي اتعلم لغة الhtml و css و جافاسكربت كم مده عشان اتعلمها ؟
نصائح و استشارات برمجية
ياجماعه اذا ابي اتعلم لغة الhtml و css و جافاسكربت كم مده عشان اتعلمها ؟
شهور، دا لو هنتكلم على نقطة انك تتقن اللغات بحيث تكون متمكن نوعا ما و واقف على رجلك