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

مساعدة

بدأه ROUA.9 في 16 مارس 2009 · 1 رد · 338 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

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

اذا ممكن تساعدوووني ، عندي واجب اني اعمل برنامج و هو :

---------------------------------------------------

PART A

Write the definition a structure type named Element_Type that represents a chemical element. The structure Element_Type should include:

• Name of the element (name) of type string.

• Atomic weight of the element (weight) of type float.

• Number of electrons in each shell (numElectrons []) which is represented by an array of int

with size 7.

Example: The chemical element SODIUM has a name Sodium, a weight 22.9898, and the number of electrons in the seven shells is:

2

8

1

0

0

0

0

PART B

1. Write a function named Average_electrons (Element_Type elt) that takes as parameters a variable of Element_Type. The function should return the average number of electrons in the element.

2. Write a function named Maximum_electrons_inShell (Element_Type elt) that takes as parameters a variable of Element_Type. The function should return the number of shell with maximum electrons.

PART C

Write a main function to test your program

--------------------------------------

و هاذه شغلي .. فيه أخطاء ابي تساعدووني فيها اذا سمحتواا ..

---------------------

#include<iostream>

#include<string>

using namespace std;

struct Element_Type

{

string name;

float weight;

int numElectrons[7];

}

void Average_electrons(Element_Type elt)

{

int sum=0;

float avg;

for(int i=0 ; i<=6 ; i++)

sum+= numElectrons;

avg= sum/7;

}

void Maximum_electrons_inShell (Element_Type elt)

{

int max;

for(int i=0 ; i<=6 ; i++)

{

max= numElectrons;

if(numElectrons < numElectrons[i+1])

max= numElectrons[i+1];

}

}

int main()

{

Element_Type elt;

float avg;

cout<<"enter chemical element:";

cin>> elt.name >> endl;

cout<<"enter weight:";

cin>> elt.weight >> endl;

cout<<"enter numElectrons:";

for (int i=0; i<6; i++)

cin>> elt.numElectrons >> endl;

return 0;

}

-------------------------------

#2

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

هناك أخطاء بسيطه ،، أولا عليك أن ترجع قيم من الدوال حتى يتسنى لك طباعتها في الداله الرئيسيه main . أيضا تعريف الstruct ينتهي دائما بفاصله منقوطه ; ، في الداله Average_electrons عليك بأن ترجع قيمه avg بعد حسابها ،، أما الداله Maximum_electrons_inShell فأنت تريد أن تعرف الموقع في المصفوفه الذي تحتوي على العدد الأكبر . لذلك يمكن أن تكون الطريقه بفرض أن الموقع الأول هو الذي يحتوي على العدد الأكبر ، ومن خلال حلقه تقوم باختبار هل الموقع الأول أكبر من الموقع i في حال تحقق ذلك ، غير ذلك الموقع الأول واجعل الموقع i هو الأكبر وهكذا حتى النهايه .. وبما أنه عليك حساب الموقع وليست القيمه فيمكن جعل متغير أخر لحفظ الindex .

أيضا في نفس الداله لكي تصل للمتغير numElectrons عليك أولا بتحدد اسم النسخه أولا ومن خلالها تقوم بالوصول للمتغير ، elt.numElectrons . وليس بمجرد كتابه numElectrons فقط ..

برنامجك بعد التعديلات :

#include<iostream>
#include<string>

using namespace std;

struct Element_Type
{
	string name;
	float weight;
	int numElectrons[7];
};

float Average_electrons(Element_Type elt)
{
	int sum=0;
	float avg;
	for(int i=0; i<=6; i++)
		sum+= elt.numElectrons;

	avg= sum/7;
	return avg;
}

int Maximum_electrons_inShell (Element_Type elt)
{
	int max =  elt.numElectrons[0];
	int index = 0;

	for(int i=1; i<=6; i++)
	{
		if( elt.numElectrons > max) {
			max= elt.numElectrons;
			index = i;
		}
	}

	return index;
}

int main()
{
	Element_Type elt;
	float avg;

	cout<<"enter name chemical element:";
	cin>> elt.name;

	cout<<"enter weight:";
	cin>> elt.weight;


	for (int i=0; i<=6; i++) {
		cout<<"enter number of Electrons in shell [" << i << "] : ";
		cin>> elt.numElectrons;
	}


	cout << "The Average of electrons : " << Average_electrons(elt) << endl;
	cout << "Maximum electrons in Shell : " << Maximum_electrons_inShell(elt) << endl;

	return 0;

}

بالتوفيق :) .

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

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