بسم الله الرحمن الرحيم
السلام عليكم ..
أسئلة برمجة C++
للدكتور محمد خالد ..
ورقة الأسئلة
و
وهي هي أكواد الحل:
حل السؤال الأول:
=============================================
// Q#1.
// Estimating the magnitued of water saved and cost of new toilets.
// By: BoYagoob;
#include<iostream>
using namespace std;
int main()
{
float oldLitersPerFlush, PersonsPerToilet, population, //Problem Inputs.
flushesPerDay, newLitersPerFlush, toiletCost; //Problem Inputs.
float dailySaving, installationCost; //Problem Outputs.
float toiletsRequired; //Additional Variable.
// storing the inputs from the user.
cout<<"Enter the old liters per flush: ";
cin>>oldLitersPerFlush;
cout<<endl;
cout<<"Enter the number of persons per toilet: ";
cin>>PersonsPerToilet;
cout<<endl;
cout<<"Enter the population: ";
cin>>population;
cout<<endl;
cout<<"Enter the flushes per day: ";
cin>>flushesPerDay;
cout<<endl;
cout<<"Enter the new liters per flush: ";
cin>>newLitersPerFlush;
cout<<endl;
cout<<"Enter the toilet cost: ";
cin>>toiletCost;
cout<<endl;
// Evaluating the toiles required.
toiletsRequired = population / PersonsPerToilet;
// Evaluating the daily saving.
dailySaving = ( oldLitersPerFlush - newLitersPerFlush ) * flushesPerDay * toiletsRequired ;
// Evaluating the installation cost.
installationCost = toiletsRequired * toiletCost;
// Displaying the magnitued of water saved and cost of new toilets.
cout<<"The magnitude of the water saved is: "<<dailySaving<<" liters/day"<<endl;
cout<<"The cost of installing new toiles is: "<<installationCost<<" QR"<<endl;
return 0;
}
============================================
حل السؤال الثاني:
===========================================
// Q#2.
// Estimating the magnitued of power of the electicity.
// By: BoYagoob;
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
const double DENSITY = 1000, GRAVITY = 9.8; //Problem Constants.
float damHeight, flowRate, conversionPercentage; //Problem Inputs //Problem Inputs.
float megawattPower; //Problem Outputs.
float conversionRate, powerProduced; //Additional Variable.
// storing the inputs from the user.
cout<<"Enter the height of the dame : ";
cin>>damHeight;
cout<<endl;
cout<<"Enter the flow rate of water: ";
cin>>flowRate;
cout<<endl;
cout<<"Enter the conversion percentage: ";
cin>>conversionPercentage;
cout<<endl;
// Evaluating the conversionRate.
conversionRate = conversionPercentage / 100;
// Evaluating the powerProduced.
powerProduced = flowRate * DENSITY * GRAVITY * damHeight * conversionRate ;
// Evaluating the megawattPower.
megawattPower = powerProduced / pow(10,6);
// Displaying the magnitued of power in megaWatts.
cout<<"The the magnitued of power in megaWatts: "<<megawattPower<<" megaWatts."<<endl;
return 0;
}
============================================
وبالتوفيق
أخوكم / بويعقوب.