السلام عليكــم ورحمـة الله وبركاتــة ،
برنامج معادلة كيميائية للغاز
المخرجات مطلوبة على ملف تكست و الشاشة
ضغط الغاز يتغير بتغير الحجم و درجة الحرارة
اكتب برنامجا يقوم باستخدام دالة لارجاع القيم (value-returning function ) للمعادلة فان در وال الكيميائية لحالة الغاز(the Van der Waal equation of state for a gas)
المعادلة
Display in tabular form the relationship between the pressure and the volume of n moles of carbon dioxide at a constant absolute temperature (T). P is the pressure in atmospheres and V is the volume in liters. The Van der Waal’s constants for carbon dioxide are: a = L2 * atm/mol2 and b = 0.0427 L/mol. The gas constant R = 0.08206 L * atm/mol * K.
انشيء جدولا يوضح العلاقة بين ضغط و حجم n مول من ثاني اكسيد الكربون في درجة حرارة مطلقة ثابتة T طبعا درجة الحرارة و P يمثل ضغط في الغلاف الجوي و V يمثل الحجم باللتر
و ثابت الفان در وال للثاني اكسيد الكربون
The Van der Waal’s constants for carbon dioxide are: a = L2 * atm/mol2
b = 0.0427 L/mol.
معامل الغاز الثابت
The gas constant R = 0.08206 L * atm/mol * K.
الادخال Input :
كل القيم المدخلة يجب ان تكون من لوحة المفاتيح (keyboard)
اسأل المستخدم الاسئلة الاتية:
the number of moles (n)
the Kelvin temperature (T)
the initial volume in milliliters
, the final volume in milliliters
the volume increment between lines in the chart.
المعالجة Processing :
اكتب حلقة تكرارية وايل (While –loop) تأخذ القيم الاولية من الحجم و الحجم النهائي بواسطة الزيادة
و استدعاء وظيفة الغاز المعطاء
وانتبه الى نوعية الداتا تايب للقيم و الوحدات
كما هو واضح ان المعادلة تتعامل باللتر فأن القيمة المدخلة بالمليمتر
, the formula assumes liters whereas the input data is in milliliters.
المخرجات البرمجية output :
الجدول لابد ان يكون منظم و مرتب مع الغاز و منسق بأربع خانات pressure )formatted to 4 digits of precision(
الاخراج مطلوب على ملف تكست و الشاشة
يعني حفظ النتائج على ملف
Result.txt
كما هو الحال في الصورة
/********************************************************************************
********
* Name: main
* Returns: int; 0 for success
*
* Purpose: to compute Van der Waals equation of state for a gas.
* Requires: stdio library function, printf, scanf,
* Dependencies: none
********************************************************************************
********/
/*includes*/
#include <stdio.h>
#include <math.h>
/*define contstants for Van der Waals' equation*/
#define R 0.08206
#define A 3.592
#define B 0.0427
/*******************************************************************
* This is the main function
********************************************************************/
void instruct(void);
int main(void)
{
double n_moles; /*the number of moles the user inputs*/
double int_volume; /*the initial volume as input by the user*/
double kelvin_temp; /*the temperature in Kelvins as input by user*/
double increment_vol; /*the increment volume given by the user*/
double final_vol; /*the final volume given by the user*/
double pressure; /*the pressure*/
double volume; /*volume*/
instruct ();
printf("\n\n\nPlease input the quanity of carbon dioxide (moles)>>");
scanf( "%lf", &n_moles);
printf("\n\nTemperature (Kelvins)>>");
scanf( "%lf", &kelvin_temp);
printf("\n\nInitial volume (milliliters)>>");
scanf("%lf", &int_volume);
printf("\n\nFinal volume (milliliters)>>");
scanf("%lf", &final_vol);
printf("\n\nVolume increment (milliliters)>>");
scanf("%lf", &increment_vol);
printf("Volume (ml) Pressure (atm)");
/*P =( nRT/(Vnb))-n^2a/V^2*/
pressure = ( n_moles*R*kelvin_temp/(volume*n_moles*B))-n_moles*n_moles*A/volume*volume;
for (volume =int_volume; volume <= final_vol; volume +=increment_vol) {
printf("\n\n%5.4lf %5.4lf\n",volume, pressure);
}
return 0;
} // end function main () **************************************
/*******************************************************************
* This is the instruct function--it gives instructions to the user
*******************************************************************/
void instruct (void)
{
printf("\n\n\nPlease enter at the prompts ");
printf("the number of moles of carbon dioxide ");
printf("the absolute\n temperature, the initial volume in millimeters ");
printf("the final volume, \nand the increment volume between lines of the table\n\n");
}