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

احتاج مساعدتكم في كتابة 4 برامج بلغة C++

بدأه ahmadssb في 9 ديسمبر 2008 · 19 رد · 3,491 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

لدي اسايمنت طلبو مننا الدكتور لكن للاسف انا بدات متاخر في الدراسة فللاسف ماعندي معلومات كفاية لحل الاسايمنت

ارشدني احد الاصدقاء لهذا المنتدى على امل انكم راح تساعدوني في محنتي

الاسايمنت عبارة عن 4 برامج بلغة C++

البرنامج اللي نستخدمه في كتابة الاكواد Crimson Editor

والكومبايلر G++

اما بالنسبة للاسايمنت انا قرات الربعة البرامج وقدرت القسمها واحللها لكن ماعرفت اكمل الباقي

انا بكتبلكم البرامج المطلوبة مع التحليل اللي سويته ما ادري ان صح ولا لا

وياريت تساعدوني في كتابة الاكواد موعد تسليم الاسايمنت يوم الخميس واختبار المادة يوم الجمعة

للاسف الوقت مرة قريب يادوب ادرس للاختبار

انا اليوم سجلت في الموقع وشفت مواضيع وكتب ودروس كثيرة ماشاء الله المنتدى مررة عجبني وراح استمر على تصفح الموقع وقراءة الدروس الموجودة كلها باذن الله

===============

Question 1 (5 marks)

Write a program that determines whether a meeting room is in violation of fire law regulations regarding the maximum room capacity. The program will read in the maximum room capacity and the number of people to attend the meeting. If the number of people is less than or equal to the maximum room capacity, the program announces that it is legal to hold the meeting and tells how many additional people may legally attend. If the number of people exceeds the maximum room capacity, the program announces that the meeting cannot be held as planned due to fire regulations and tells how many people must be excluded in order to meet the fire regulations.

عندنا غرفة اجتماعات ونود معرفة قانون الحريق

ونود معرفة كحد اقصى لعدد الاشخاص

مدخلات = سعة غرفة الاجتماعات وعدد الاشخاص اللي يحضرون الاجتماع

المخرجات = نتيجة مسموح لعقد الاجتماع اولا

التحليل : 1) اذا كان عدد الاشخاص اقل من او يساوي لسعة الغرفة

اذن يعطي نتيجة مسموح لعقد الاجتماع وكم شخص ممكن ينضافوا الى الاجتماع

2) اذا كان عدد الاشخاص اكثرمن سعة الغرفة

اذن يعطي نتيجة غير مسموح لعقد الاجتماع وكم شخص ممكن يستبعدوا من الاجتماع

Question 2 (5 marks)

Write a program that asks the user to enter a number of seconds

  • There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.
  • There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater than or equal to 3600, the program should display the number of hours in that many seconds.
  • There are 60 seconds in a minute. If the number of seconds entered by the user is less than 3600, but is greater than or equal to 60, the program should display the number of minutes in that many seconds.

المدخلات = عدد الثواني

المخرجات = تحديد كم عدد الايام او الساعات او الدقائق من الثواني

بشرط

اليوم = 86400 ثانية ، اذا كان الرقم المدخل اكبر او يساوي 86400 سوف تظهر كم عدد الايام

الساعة =3600 ثانية اذا كان الرقم المدخل اقل من86400 ولكن اكبر اويساوي 3600سوف تظهر كم عدد الساعات

الدقيقة = 60 ثانية اذا كان الرقم المدخل اقل من 3600 ولكن اكبر من اويساوي 60 سوف تظهر كم عدد الدقائق

Question 3 (5 marks)

Assuming the level of the Earth’s oceans is currently rising at about 1.5 millimetres per year; write a program that displays a table showing the total number of millimetres that the oceans will have risen each year for the next 25 years.

افترض انه مستوى محيطات الارض تغرق بمعدل 1.5 مل في السنة

المخرجات السنة الاولى * 1.5

السنة الثانية = مجموع السنة الاولى * 1.5

السنة الثالثة = مجموع الثانية * 1.5

.

.

.

.

.

وهكذا

Question 4 (5 marks)

In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy:

KE = ½ mv2

The variables in the formula are as follows: KE is the kinetic energy in joules, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second.

Write a function named kineticEnergy that accepts an object’s mass (in kilogram) and velocity (in meters per second) as arguments. The function should return the amount of kinetic energy that the object has. Demonstrate the function by calling it in a program that asks the user to enter values for mass and velocity. >

برنامج تستخدم المعادلة اللي فوق

المدخلات الحجم وحاجة ثانية ما اعرف معناها في الفيزياء

والمخرجات KE

============================

اتمنى منكم المساعدة العاجلة

أخوكم \ أحمد

#2

هذه واجب ، المنتدى يمنع حل الواجبات

-----------

على فكرة ، لو عندك معرفة يومين فى السى++ تستطيع حل هذا الواجب ، كما أن الطلبات موضحة بخوارزميات الحل ، يعنى ما لك عذر :)

#3

اوكي انا بحل الواجب لكن محتاج مساعدتكم في الكود

راح اسوي اللي اقدر عليه وبتوكل على الله ثم عليكم

بس اصبر علي اليوم بحاول فيه وبسيب الاختبار شوي

ياريت ماتحذفو الموضوع لمدة ما ارجع

#4

هذا حل للسؤال الاول

اقتباس
#include <iostream>

using namespace std;

int main() {

int room , people , allow ;

cout << "This This program determines whether a meeting room is in violation of fire law regulations regarding the maximum room capacity. \n";

cout << "put maximum room capacity. \n";

cin >> room ;

cout << "put the number of people to attend the meeting. \n";

cin >> people ;

if( people <= room)

{

cout << "It is Allow to hold meeting\n";

cin >> allow = room - people;

cout << "there is \n" ;

cout << allow ;

cout << "allow persons to join in meeting\n"

}

else

{

if( people > room)

{

cout << "It is not Allow to hold meeting\n";

cin >> allow = people - room;

cout << "there is \n" ;

cout << allow ;

cout << " persons not allow to join in meeting\n"

}

}

}

وطلعت معاي هذه الاخطاء

اقتباس
q1.cpp: In function `int main()':

q1.cpp:14: error: no match for 'operator=' in '(&std::cin)->std::basic_istream<_

CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char

>](((int&)(&allow))) = (room - people)'

c:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iosfwd:62: n

ote: candidates are: std::basic_istream<char, std::char_traits<char> >& std::bas

ic_istream<char, std::char_traits<char> >::operator=(const std::basic_istream<ch

ar, std::char_traits<char> >&)

q1.cpp:18: error: expected `;' before '}' token

q1.cpp:24: error: no match for 'operator=' in '(&std::cin)->std::basic_istream<_

CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char

>](((int&)(&allow))) = (people - room)'

c:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iosfwd:62: n

ote: candidates are: std::basic_istream<char, std::char_traits<char> >& std::bas

ic_istream<char, std::char_traits<char> >::operator=(const std::basic_istream<ch

ar, std::char_traits<char> >&)

q1.cpp:28: error: expected `;' before '}' token

تم تعديل هذه المشاركة بواسطة ahmadssb في 9 ديسمبر 2008 في 18:24

#5

هذا السؤال الثاني

اقتباس

#include <iostream>

using namespace std;

int main() {

int s , d , h , m ;

cout << "Enter a number of seconds : \n";

cin >> s ;

if( s >= 86400)

{

cout << "the number of days in that many seconds: ";

cin >> d = s / 86400;

cout << d ;

}

else

{

if( 86400 > s >= 3600)

{

cout << "the number of hours in that many seconds: ";

cin >> h = s / 3600;

cout << h ;

}

}

else

{

if( 3600 > s >= 60)

{

cout << "the number of minutes in that many seconds: ";

cin >> m = s / 60;

cout << m ;

}

}

}

وهذه الاخطاء اللي جاتني

اقتباس

q2.cpp:11: error: no match for 'operator=' in '(&std::cin)->std::basic_istream<_

CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char

>](((int&)(&d))) = (s / 86400)'

c:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iosfwd:62: n

ote: candidates are: std::basic_istream<char, std::char_traits<char> >& std::bas

ic_istream<char, std::char_traits<char> >::operator=(const std::basic_istream<ch

ar, std::char_traits<char> >&)

q2.cpp:20: error: no match for 'operator=' in '(&std::cin)->std::basic_istream<_

CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char

>](((int&)(&h))) = (s / 3600)'

c:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/iosfwd:62: n

ote: candidates are: std::basic_istream<char, std::char_traits<char> >& std::bas

ic_istream<char, std::char_traits<char> >::operator=(const std::basic_istream<ch

ar, std::char_traits<char> >&)

q2.cpp:25: error: expected primary-expression before "else"

q2.cpp:25: error: expected `;' before "else"

q2.cpp:35:2: warning: no newline at end of file

q2.cpp: In function `int main()':

#6

عرفت الخطا اللي في البرنامج الاول

كنت ناسي احط علامة ; في اخر البرنامج

كما انه اعتقد بسبب الاسطر

cout << "there is \n" ;

cout << allow ;

cout << " persons not allow to join in meeting\n"

خلتها في سطر واحد واشتغل البرنامج الحمد لله

هذا البرنامج بعد التعديل ابى بس اعدل في تعبير الكلام ما ادري اذا كان التعبير مناسب ام لا

اقتباس
#include <iostream>

using namespace std;

int main() {

int room , people , allow ;

cout << "This This program determines whether a meeting room is in violation of fire law regulations regarding the maximum room capacity. \n";

cout << "put maximum room capacity. \n";

cin >> room ;

cout << "put the number of people to attend the meeting. \n";

cin >> people ;

if( people <= room)

{

cout << "It is Allow to hold meeting\n";

allow = room - people;

cout << "there is " << allow << " persons allow to join in meeting\n";

}

else

{

if( people > room)

{

cout << "It is not Allow to hold meeting\n";

allow = people - room;

cout << "there is " << allow << " persons not allow to join in meeting\n";

}

return 0;

}

}

اما البرنامج الثاني كنت ناسي علامة ; في كل شرط وقل اللخبطة حق الايرور اللي ما فهمت منها شي

اقتباس
#include <iostream>

using namespace std;

int main() {

int s , d , h , m ;

cout << "Enter a number of seconds : \n";

cin >> s ;

if( s >= 86400)

{

d = s / 86400;

cout << "the number of days in that many seconds: " << d;

}

else

{

if( 86400 > s >= 3600)

{

h = s / 3600;

cout << "the number of hours in that many seconds: " << h;

}

}

else

{

if( 3600 > s >= 60)

{

m = s / 60;

cout << "the number of minutes in that many seconds: " << m ;

}

}

}

طلع معي هذا الايرور

اقتباس
q2.cpp: In function `int main()':

q2.cpp:23: error: expected primary-expression before "else"

q2.cpp:23: error: expected `;' before "else"

#7

البرنامج الثالث انا كتبته بطريقة بدائيى وما اعتقد انها الطريقة الصحيحة اللي طالبها الدكتور

هذه الكوج للبرنامج الثالث

اقتباس
#include <iostream>

using namespace std;

int main() {

double y1 , y2 , y3 , y4 , y5 , y6 , y7 , y8 , y9 , y10 , y11 , y12 , y13 , y14 , y15 , y16 , y17 , y18 , y19 , y20 , y21 , y22 , y23 , y24 , y25 ;

cout << "Assuming the level of the Earth's oceans is currently rising at about 1.5 millimetres per year.. \n" ;

y1 = 1 * 1.5;

cout << "1- " << y1 << " millimetres . \n";

y2 = y1 * 1.5;

cout << "2- " << y2 << " millimetres . \n";

y3 = y2 * 1.5;

cout << "2- " << y3 << " millimetres . \n";

y4 = y3 * 1.5;

cout << "2- " << y4 << " millimetres . \n";

y5 = y4 * 1.5;

cout << "2- " << y5 << " millimetres . \n";

y6 = y5 * 1.5;

cout << "2- " << y6 << " millimetres . \n";

y7 = y6 * 1.5;

cout << "2- " << y7 << " millimetres . \n";

y8 = y7 * 1.5;

cout << "2- " << y8 << " millimetres . \n";

y9 = y8 * 1.5;

cout << "2- " << y9 << " millimetres . \n";

y10 = y9 * 1.5;

cout << "2- " << y10 << " millimetres . \n";

y11 = y10 * 1.5;

cout << "2- " << y11 << " millimetres . \n";

y12 = y11 * 1.5;

cout << "2- " << y12 << " millimetres . \n";

y13 = y12 * 1.5;

cout << "2- " << y13 << " millimetres . \n";

y14 = y13 * 1.5;

cout << "2- " << y14 << " millimetres . \n";

y15 = y14 * 1.5;

cout << "2- " << y15 << " millimetres . \n";

y16 = y15 * 1.5;

cout << "2- " << y16 << " millimetres . \n";

y17 = y16 * 1.5;

cout << "2- " << y17 << " millimetres . \n";

y18 = y17 * 1.5;

cout << "2- " << y18 << " millimetres . \n";

y19 = y18 * 1.5;

cout << "2- " << y19 << " millimetres . \n";

y20 = y19 * 1.5;

cout << "2- " << y20 << " millimetres . \n";

y21 = y20 * 1.5;

cout << "2- " << y21 << " millimetres . \n";

y22 = y21 * 1.5;

cout << "2- " << y22 << " millimetres . \n";

y23 = y22 * 1.5;

cout << "2- " << y23 << " millimetres . \n";

y24 = y23 * 1.5;

cout << "2- " << y24 << " millimetres . \n";

y25 = y24 * 1.5;

cout << "2- " << y25 << " millimetres . \n";

}

#8

هذا البرنامج الاخير

ما عرفت اخليه يضرب في 1/2

خليتها 1.5

هذا الكود ::

اقتباس
#include <iostream>

using namespace std;

int main()

{

double KE , m , v;

cout << "Enter value for mass in kilogram\n";

cin >> m ;

cout << "Enter value for velocity in meters per second\n";

cin >> v ;

if (KE = 1.5 * m*v*v)

{

cout << " The value for kinetic Energy = " << KE ;

}

}

#9

ياريت احد يساعدني هل الاكواد صحيحة

خصوصا البرنامج الثاني والثالث

وفي البرنامج الاول ياريت لو احد يعطيني تعبير في النص افضل من اللي انا وضعته

والبرنامج الاخير هل لو خليته 1.5 صح ولا لازم اخليه 1/2 وكيف اسويها لانه البرنامج وقف ما طلع لي ناتج ال KE

#10

ياجماهعة الخير بليز ردوا علي

#11

انت تقصد تبي تضربه في نص ؟؟

هذا تعديل على جوابك اخي

اتمنى يكون الجواب واضح

 

#include <iostream.h>
int main()
{
double KE , m , v;
cout << "Enter value for mass in kilogram\n"; 
cin >> m;
cout << "Enter value for velocity in meters per second\n";
cin >> v;
if (KE =  m*v*v*0.5)
{
cout << " The value for kinetic Energy = " << KE <<'\n';
}
}

FineDesign For Graphic and WebDesign

ForEach(Minute in MyLife)

MyExperience ++;

#12

أخي احمد لو وضعت كل سؤال في مشاركة + محاولتك كان افضل . وضع عدة اسئلة في مشاركة واحده غير مريح.

tvquran_6.gif

#13

هذا تصحيح الكود حق السؤال الثاني

#include <iostream.h>


int main() {
int s , d , h , m;
cout << "Enter a number of seconds : \n"; 
cin >> s;
if( s >= 86400)
{
d = s / 86400;
cout << "the number of days in that many seconds: " << d;

}
else
{
if( 86400 >s && s >= 3600)
{
h = s / 3600;
cout << "the number of hours in that many seconds: " << h;


}
else if( 3600 >s && s >= 60)
{
m = s / 60;
cout << "the number of minutes in that many seconds: " << m<<'\n';

}
}

}

FineDesign For Graphic and WebDesign

ForEach(Minute in MyLife)

MyExperience ++;

#14

مرحبا عزيزي

اسف ما اقدر افيدك لان وقتي مو ملكي لكن بشكل عام

1.5 اعتقد تنفع

خصوصا لو تعطيك نتائج صحيحة بالاله الحاسبة طبعا في حالة سويت عملية trace ووضعت قيم صحيحة

ثاني شئ الخطأ في السؤال الثاني متعلق بـ else

طبعا ماراجعت الكود لكن اعقد انه سهل ركز في الاقواس غالبا يون فيها الغلط

لي عودة ان شاء الله في حالة فراغي

اتمنى لك التوفيق

#15

شكرا لك اخ ibu_love على المساعدة فعلا انا اصلا كنت غلطان كنت كاتبها 1.5 هي بس 0.5

اخ suns شكرا لك على التوضيح و أنا بانظارك

مشرف

تم تعديل هذه المشاركة بواسطة ahmadssb في 10 ديسمبر 2008 في 22:29

#16

بالنسبة للسؤال الثالث اخوي أعتقد انه بإمكانك تعمل LOOP يمر على السنوات اللي بدك تجمعها بس رح يطلعلك مجموع السنوات كاملة بمتغير تاني ، لكن طريقتك منيحة مع انها طويلة جداً ، بس بعتقد انها بتنحل بطريقة اخرى ، ومالك حد يحلها الك الى الاخ المشرف فهــد الشلــوي .....

FineDesign For Graphic and WebDesign

ForEach(Minute in MyLife)

MyExperience ++;

#17

بالنسبة للكود في البرنامج الثاني قبل ما يعدله لي الاخ ibu_love كان في خطا في الاقواس في Else كما قال الاخ suns

كان الخطا في القوس اللي قبل else الاخيرة شلته ووضعتها في اخر الامر اشتغل معاي البرنامج

لكن للاسف اظهر فقط عدد الايام لكن عندما طلبت رقم اقل ليظهر ناتج الساعات والدقائق لم يظهر لي شي كانه البرنامج انتهى ماادري اش المشكلة

هذا الكود بعد التصحيح :

اقتباس
#include <iostream>

using namespace std;

int main() {

int s , d , h , m ;

cout << "Enter a number of seconds : \n";

cin >> s ;

if( s >= 86400)

{

d = s / 86400;

cout << "the number of days in that many seconds: " << d;

}

else

{

if( 86400 > s >= 3600)

{

h = s / 3600;

cout << "the number of hours in that many seconds: " << h;

}

else

{

if( 3600 > s >= 60)

{

m = s / 60;

cout << "the number of minutes in that many seconds: " << m ;

}

}

}

}

#18

شكرا لك اخ ibu_love على كل شي

لقد اكتشت للتو ان C++ لا تقبل المعادلات الرياضية كما هي 86400 > s >= 3600 بعكس الفيجوال بيسك

لازم افصل بين المعادلتين بعلامة && اعتقد معناها (و)

طيب اش في علامات غيرهم عشان مرة وحدة افهمها

#19

العفو اخوي هذا واجبنا ،،،

نعم علامة && هي (و) ويوجد أيضاً || وهي تعني (أو) وهذه ستستخدمها كثير في لغة السي ، أكيد في فارق بين الفيجيوال والسي ، الفيجيوال تكتب فيها and بدل && و or بدل || ، وفي الاشارات المنطقية تلاقيها في الكتب العربية الموجودة في المنتدى ولكن أكثرها نفس اللي تستخدمه في الفيجيوال بيسيك ، واللغتين على فكرة نفس المنطق بس الستركتشر بيختلف لا أكثر .

وان شاءالله نقدر نساعدك على طول اخوي ...

FineDesign For Graphic and WebDesign

ForEach(Minute in MyLife)

MyExperience ++;

#20

سويت الكود الثالث بطريقة اللوب لكن للاسف الناتج مختلف

اقتباس
int main() {

double x;

for ( int i = 1; i < 26; i++)

{

x = i * 1.5;

cout << "Y" << i<<"\t"<<x<<endl;

}

return 0;

لكن للاسف انا ماقدرت اخليه يضرب ناتج السنة السابقة في 1.5 خليته يضرب رقم السنة في 1.5

في احد ممكن يساعدني لاني لازم اسلمه بكرة

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…