الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ممكن اعرف مشكلة هذا الكود

بدأه small في 23 ديسمبر 2008 · 4 رد · 706 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه

ارجوكم ساعدوني في كود

هذا السؤال

Write a C++ program that do the following:

a. Define a class called PowerOper that stores two pieces of information: the base and the exponent.

b. Define Set and Get functions for your class data members.

c. Define a member function called Power that prints the result of (base)power.

d. Define a member function called Validate that to check if exponent is a positive and nonzero integer.

e. The function Power should continue calling Validate before calculating the result until a valid exponent is entered by the user.

f. Define function Menu that print choices (i.e.1. calculate the power, 2. Exit). These choices must be repeated until the user selects exit. This function should call the corresponding calculating function based on the user's choice.

g. Declare an object of type Power and test your class.

وهذا الكود

المشكله انه ما يسوي run

#include <iostream>

#include <cmath>

using namespace std;

class PowerOper

{

private:

double base;

double exponent;

public:

void setbase(double d){

base=d;

}

void setexpon(double p){

exponent=p;

}

double getbase(){

return base;

}

double getexpon(){

return exponent;

}

double valid (double d){

do{

cout<<"enter valid exponent";

cin>>d;

}while (d<0);

return d;

}

void Power (double f,double d){

double h,powe;

h= double valid (double d);

powe=pow(d,h);

cout<<"power is "<<pow<<endl;

}

void mm (){

cout<<"1. calculate the power, 2. Exit ";

}

}

int main ()

{

PowerOper asd;

int y;

double d,f,k;

do {

asd.mm();

cout<<"enter you choice";

cin>>y;

cout<<"enter base";

cin>>f;

asd.setbase(double f)

cout<<"enter exponent";

cin>>k;

d=asd.double valid (double k);

asd.setexpon(double d);

Power (double f,double d);

}while(y!=2);

system("pause");

return 0;

}

وشكرااااااااااااااااااااااا

#2
#include <iostream>
#include <cmath>
using namespace std;

class PowerOper
{
private: 
	double base;
	double exponent;
public:
	void setbase(double d){
		base=d;
	}
	void setexpon(double p){
		exponent=p;
	}
	double getbase(){
		return base; 
	}

	double getexpon(){
		return exponent; 
	}
	double valid (double d){

		do{
			cout<<"enter valid exponent";
			cin>>d;
		}while (d<0);
		return d;
	}



	void Power (double f,double d){
		double h,powe;
		h= valid(d);
		powe=pow(d,h);
		cout<<"power is "<<pow<<endl;
	}
	void mm (){
		cout<<"1. calculate the power, 2. Exit ";
	} 
};

int main ()
{
	PowerOper asd;
	int y;
	double d,f,k;
	do {
		asd.mm();
		cout<<"enter you choice";
		cin>>y;
		cout<<"enter base";
		cin>>f;
		asd.setbase( f);
			cout<<"enter exponent";
		cin>>k;
		d=asd. valid ( k);
		asd.setexpon( d);
		asd.Power ( f, d);

	}while(y!=2);

	system("pause");
	return 0;
}

موقع كلية الحاسب الآلي ونظم المعلومات.

WWW.UQUCS.COM

#3

المشكلة في الاقواس ,, تأكد منها

llback.jpg

اشهد ان لا إله إلا الله وان محمدا ً رسول الله

#4

بســم الله الـرحمــن الرحيــم

في مثالك حالة الاحرف كبيرة في كلمتي

namespace , class

وهذا طلبك

  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class PowerOper
  7. {
  8.  
  9. public:
  10.  
  11. double getbase();
  12. double getexpon();
  13.  
  14. void setbase(double b);
  15. void setexpon(double p);
  16. void Power();
  17.  
  18. protected:
  19. void Validate();
  20.  
  21. private:
  22. double base;
  23. double exponent;
  24.  
  25. };
  26.  
  27.  
  28. void PowerOper::setbase(double b)
  29. {
  30. base = b;
  31. }
  32.  
  33. void PowerOper::setexpon(double p)
  34. {
  35. exponent = p ;
  36. }
  37.  
  38. double PowerOper::getbase()
  39. {
  40. return base ;
  41. }
  42.  
  43. double PowerOper::getexpon()
  44. {
  45. return exponent ;
  46. }
  47. void PowerOper::Power()
  48. {
  49. Validate();
  50. cout << "Result = " << pow(base , exponent) << endl;
  51. }
  52.  
  53.  
  54. void PowerOper::Validate()
  55. {
  56. double expon ;
  57. while( getexpon() <= 0)
  58. {
  59. cout << "Enter Vaild Exponent! : " ;
  60. cin >> expon ;
  61. setexpon(expon);
  62. }
  63.  
  64. }
  65.  
  66.  
  67.  
  68. int Menu()
  69. {
  70. int choice ;
  71. while(choice != 1 && choice !=2)
  72. {
  73. cout << "1. calculate the powern" << "2. Exitn" ;
  74. cin >> choice ;
  75. if(choice == 2 )
  76. {
  77. exit(0) ;
  78. }
  79. }return 0;
  80. }
  81.  
  82. int main()
  83.  
  84. {
  85. cout << "enter your choice !" << endl;
  86.  
  87. Menu();
  88.  
  89. PowerOper pwr ;
  90. double bs ,exp ;
  91.  
  92. cout << "Enter Base :" ;
  93. cin >> bs ;
  94. pwr.setbase(bs);
  95.  
  96. cout << "Enter Exponent :" ;
  97. cin >> exp ;
  98. pwr.setexpon(exp);
  99.  
  100. pwr.Power();
  101.  
  102. return 0;
  103.  
  104.  
  105. }
  106.  

تحياتي

while( "اسلام" )
{
 cout >> "الموت لبني صهيون" >> endl;
}
return "فلسطين";
#5

السلام عليكــم ورحمـة الله وبركاتــه

مشكورين اخواني الله يعافيكم

استفدت

شكرا جزيلا

مواضيع مشابهة