c++ chapter (1)may 2014 ينورتكللإا ديربلاب وأ 9 4444 062 ةيصن ةلاسرب...
Post on 28-Jan-2020
2 Views
Preview:
TRANSCRIPT
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
C++
Chapter (1):
Introduction to C++
Chapter (2):
Control Statements
):3Chapter (
unctionsF
مذكرات شرح وتمارين محلولة،
من المواد أدناه سابقة للعديد امتحانات
ن أدناهالموقعين المذكوري متاحة مجانا على
حين يكون المثل األعلى لألمة صغيرا
.يصغر معه كل أبناء األمة
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
1Chapter
to C++ Introduction
مذكرات شرح وتمارين محلولة،
من المواد أدناه سابقة للعديد امتحانات
الموقعين المذكورين متاحة مجانا على
أدناه
حقوووول العبووواد ه يغسووولما الحووو كموووا
.أو معنوية يعتقد البعض، مادية كانت
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
% (، ) / التعامل مع كيفية
.بدون كسور صحيحفي حال قسمة رقم صحيح على رقم صحيح آخر ينت رقم *
11 / 3 = 3, 7 / 5 = 1, 18 / 6 = 3
.يحالصح باقي القسمة بين رقمين صحيحين ينت % في حال استخدام *
11 % 3 = 2, 7 % 5 = 2, 18 % 6 = 0
.فإن ذلك يعني أن الرقم األول هو أحد مضاعفات الرقم الثاني صفرا في حال كون الباقي *
15 % 3 = 0 (15 is multiple of 3)
. أيضا كسريا يكون العملية الرياضيةحد أو كال الرقمين كسريا فإن نات إذا كان أ *
10 / 4.0 = 2.50, 4.0 / 8 = 0.5, 5.0 / 2.0 = 2.50
تنطبق على كل عالمات (صحيحة أم كسرية)بنوات العمليات الرياضية الخاصة القاعدة السابقة *
* (. ,/ , + , - ) األخرى مثل العمليات الحسابية
يكون ، وا زوجيالرقم كان إذا صفرا فإن الباقي يكون 0رقم صحيح على ةمفي حال قس *
.ا الرقم فرديكان إذا ( -1، + 1)
7 % 2 = 1, -7 % 2 = -1, 12 % 2 = 0, -12 % 2 = 0
.الخاناتباقي ونات القسمة هوخانة اآلحاد ي هو فإن الباق( 12)في حال التقسيم على *
50 / 10 = 5, 53 / 10 = 5, 53 % 10 = 3, 297 % 10 = 7
.الصفحة التالية تحتوي على أمثلة إضافية للقواعد المذكورة أعاله*
Division operator Modulus operator
.اإلحسان يحط من قدر من يتلقونه
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Modulus & Division Operators ( % / )
Find the result of the following expressions:
5 / 2; 5 % 2; 5.0 / 2;
15 / 5; 15 % 5; 15 / 5.0;
4 / 8; 4 % 8; 2.0 / 4.0;
Note: (%) works only with integers.
C ++ عمليات الضرب والتقسيم لما طعم جديد مع
Find the result of the following expressions:
18 % 2; -18 % 2; 19% 2; -19 % 2;
276 / 10; 276 %10; 2532 % 10; 2532 / 10;
276/100; 2.76*100; 949%100; 734%150;
0
27 6
2
(± ve) even % 2 ► zero
(+ ve) odd % 2 ► 1
(- ve) odd % 2 ► -1
small integer / big integer ► zero
small integer % big integer ► small
integer / integer ► integer
fraction / integer ► fraction
integer / fraction ► fraction
fraction / fraction ► fraction
0
2 1 2.5
0 3.0 3
4 0.50 0
1 -1
2 253
276.0 49 134
(Multiple)
* (، + ، -) ات وكذلك الحال لباقي العملي
ه تمنعن أناسا من عبور النمر
.عندما يكون في قاربك مكان
integer % 10 ► خانة اآلحاد
integer / 10 ► باقى الخانات
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
same
(Level of Precedence)
ترتيب األولويات
(1) ( ) left to right also in to out
(2) / % * left to right all same level
(3) + - left to right all same level
left to right all same level (للسؤال) =! == (4)
(5) > < >= <= left to right all same level
(6) && ( شرطينلدم ) left to right
(يكفي تحقق أحد الشرطين) || (7) left to right
(8) = += *=
sum = sum + x
sum += x
Arithmetic
Operators
Assignment
Operators
Parentheses
Equality
Operators
2 * 6 % 4; ► 4 (wrong)
is not equivalent to:
2 * 6 % 4; ► 0 (correct)
من األفضل أه تكون موجودا
.على أن تعيش بدناءة
Relational
Operator
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Mathematical Expressions
Find the result of the following expressions:
1) x = 2+3 * 4;
2 +12
14
1) y = 7 / 3 + 3 % 2;
1 + 2
3
2) z = ((7) * (3) + (5 + (3)));
7 * 3 5 + 3
21 + 8
29
Find the result of the following expressions:
3) t = (13 / 8 * (2) + 5 * (7)/3);
1 * 2 35 / 3
2 + 11
13
4) b = (13) * (2 / 4.0) - 7;
13 * 0.5
6.5 - 7
-0.5
5) f = ((5-1) * 2.5 - 14 % (20)/2); 4 * 2.5 14 / 2
10.0 - 7
3.0
x = 14
z = 29
t = 13
b = - 0.50
f = 3.0
ارتكب جريمة وسوف تتحول
. كل صيحة حولك كأنما عليك
y = 3
Tricky
Exam
Output
s
ترتيب تمارين على
العمليات أولويات
الحسابية
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
ثوابت متغيرات
Constants Variables (Ex: e , pi )
لما عدة تقسيمات
Data Types أنواع البيانات
نصية رقمية
Numerical Text
integral fraction character string
ةأرقام كسرية أرقام صحيح حرف واحد كلمة أو
عدة كلمات
شروط تسمية مخازن البيانات
Variables' names
كلمات ه يمكن أن يكون أحد (3): تتكون من (0) .ه تبدأ برقم (1)
.عن محتواها المرتقب يفضل أن تكون أسماء المخازن معبرة *
والحرف األول من كل Smallبحروف ن الكلمة األولىو أكثر تكوفي حال تركيب االسم من كلمتين أ *
. Capitalكلمة تالية
: لكن أشهرها ما يلي++ ع بيانات أساسية عديدة بلغة السيتوجد أنوا *
Letters.حروف -1
.Digitsأرقام -2
.تحتية شرطة -3
المحجوزة ++ لغة السي
.(cout) مثل
البعض يرى الحياة مجرد تنافس في
.أن تكون الجاني ليس المجني عليه
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
(C++ data types)
(C++ variable names)
:شروط تسمية المتغيرات
. أه يبدأ برقم( 1
(. under_scoreيمكن أن يبدأ بحرف أو شرطة تحتية )
، وكذلك الـ letters (A, B, C . . . Z, a, b, c . . . z) ،digits (0, 1, 2 . . . 9)يمكن أن يحتوي على ( 0
under_score فقط.
:في األسماءوبالتالي كل العالمات التالية مرفوضة
" ‘: ; .| / space ؟ { } [ ]> < + = -* ( ) ^ & % @ # $ ! ~
(reserved words) أه يحتوي على أحد الكلمات المحجوزة للغة السي (3
:كل الكلمات التالية مرفوضة في األسماء
(main, int, float, char, bool, long, void, double, const, return )
:مع برنام السي وكذلك األوامر الخاصة بالمكتبات المدرجة
(cout, cin, if, else, for, while, do, switch, case, default, break, continue )
double x, 3y, x100y, x_y, x-y, "grade", int1, _z;
char x&y, x+y, Name, name, return, character;
int integer, Main, _7, int_char, x y;
البعض يممه اهنضمام إلى الجممور
.أكثر من انضمامه إلى الحق
variables
numbers text
int double char string
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
output statement (cout)
find the exact output:
1) cout << "Welcome to C++\nagain\n";
Welcome to C++
again
2) A = 50; cout << "To get " << A*2 << " in C++ \nis possible" << endl;
To get 100 in C++
is possible
3) a = 4; b = a*3+2; cout << "a = " << a << endl << "b << = " << b;
a = 4
b << = 14
تطبع كما هي" " عالمات التنصيصداخل >>
4) x = 3; cout << x << " is same like: " << 4.5 * 2 / 3 << endl;
3 is same like: 3.0
5) i = 3; j = i/2 + 1; cout << i – j << " != " << "\n j – i \n";
1 !=
j – i
6) cout << "***\n" << "**" << "endl" << "*";
***
**endl*
endl تطبع كما هي" " عالمات التنصيصداخل
you can use single
quotes for one
character '*'
الشمعة ه تخسر شيئا حين
.تـشعل شمعة أخرى
Place messages
in double quotes
endl
is equivalent to:
"\n"
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
كتابة البرام
أجزاء البرنام الرئيسية
البرنام مقدمة قراءة المدخالت تعريف المتغيرات المخرجات الحسابات
Output Processing Input Variables'
decelaration
(1) (2) (3) (4)
# include <iostream>
using namespace std;
int main ( )
{
int x, y;
double avg;
cout << "enter 2 integers: ";
cin >> x >> y;
sum = x + y;
avg = sum / 2.0;
cout << "total = " << sum << endl;
cout << "Average = " << avg << endl;
return 0;
}
(1)
(2)
(3)
(4)
امنح الناس دائما أكثر مما
.يتوقعون الحصول عليه
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
irst program)F(
Write a program that reads three integers and prints their total, product
and average.
# include <iostream>
using namespace std;
int main ( )
{
int x, y, z;
(1) int total, prod;
double avg;
cout << "Enter three integers: ";
(2)
cin >> x >> y >> z;
total = x + y + z;
(3) prod = x * y * z;
avg = total / 3.0;
cout << "Total = " << total << endl;
(4) cout << "Product = " << prod << endl;
cout << "Average = " << avg << endl;
return 0;
}
Enter three integers: 7 11 5
Total = 23
Product = 385
Average = 7.66667
Always empty
parentheses
إذا قدمت معروفا ألحد، ه تنتظر إيصاه
.بعلم الوصول أو خطاب شكر
:يتكون جسم أي برنام من أربعة أقسام
.تعريف المتغيرات -1
.قراءة المدخالت -0
.إجراء العمليات -3
.إظمار النتائ -4
أي برنام بأي لغة يتكون
.أربعة أجزاء بعد المقدمةمن
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
(Modulus Operator)
Write a program that reads a two-digit integer and prints the sum and the
product of its digits.
# include <iostream>
using namespace std;
int main ( )
{
int n, d1, d2;
cout << "Enter a 2-digits integer: ";
cin >> n;
d1 = n % 10;
d2 = n / 10;
cout << "Sum of digits is: " << d1 + d2 << endl;
cout << "Product is: " << d1 * d2 << endl;
return 0;
}
Enter a 2-digits integer: 53
Sum of digits is: 8
Product is: 15
بعض الناس شرفاء، لكن يحزنمم أن
.يكونوا كذلك دون ثناء أو مقابل
المطلووووووب قوووووراءة رقوووووم
واحوووووود يحتوووووووي علووووووى
.خانتين وليس رقمين
لفصل أي رقم إلى خاناته
x%10 ،x/10 نستخدم
.الرقم حسب عدد خانات
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
يعطيك مش الزم
الحاالت كل
(Simple-if-statement)
Write a program that asks the user to enter two integers, obtain the
numbers from the user, then print the larger number followed by the words
"is larger.", if the numbers are equal, print the message "these numbers are
equal."
# include <iostream>
using namespace std;
int main ( )
{
int x , y;
cout << "Enter two integers: ";
cin >> x >> y;
if ( x > y )
cout << x << " is larger."<< endl;
if ( y > x )
cout << y << " is larger."<< endl;
if ( x == y )
cout << "These numbers are equal." << endl;
return 0;
}
Enter two integers: 9 11
11 is larger.
Enter two integers: 11 11
These numbers are equal.
بعووووض النوووواس هممووووم تحقيووووق أحالممووووم،
.والبعض اآلخر هممم هدم أحالم اآلخرين
ifنسوووووووووووتخدم جملوووووووووووة
الشوووورطية للسووووؤال عوووون
.تحقق شرط من عدمه
فوووي حوووال السوووؤال عووون
خدم تساوي رقموين نسوت
.واحدة= وليس = =
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Enter the object mass: 15
Enter the object volume: 30
This object floats, its density is 0.5
(Simple-if-statement)
Write a program that asks the user to enter two integers that represent the
mass & volume of an object determine whether the object will float or sink.
Note:
Density = Mass / Volume;
If density < 1 then the object floats, otherwise it sinks.
# include <iostream>
using namespace std;
int main ( )
{
int mass, vol;
double den;
cout << "Enter the object mass: ";
cin >> mass;
cout << "Enter the object volume: ";
cin >> vol;
den = mass * 1.0 / vol;
if ( den < 1 )
cout << "This object floats, its density is " << den << endl;
if ( den > 1 )
cout << "This object sinks, its density is " << den << endl;
return 0;
جميل أن يموت اإلنسان من أجل هدف {
.عظيم، وأجمل من ذلك أن يعيش ألجله
مووووون نووووووع denه يكفوووووي أن تكوووووون
double بل يجب أن يكون أحود طرفوي
.كذلك doubleن نوع التقسيم م
ا كسري البسط أو المقاميكون أن البد
.ا حتى يكون الناتج كسري
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Exercise 1.16: Write a single C++ statement or line that accomplishes each
of the following:
a) Print the message "Enter two numbers".
cout << "Enter two numbers";
b) Assign the product of variables b and c to variable a.
a = b * c;
c) State that a program performs a sample payroll calculation (use text that
helps to document a program).
// This program performs a sample payroll calculation.
d) Input three integer values from the keyboard into integer variables a, b
and c.
cin >> a >> b >> c;
حتى إذا فعل خمسون مليون شخص
فعال أحمقا، سيزال هذا الفعل أحمقا؟
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Exercise 1.18: Fill in the blanks in each of the following:
a) What arithmetic operations are on the same level of precedence as
multiplication? ____________________.
b) When parentheses are nested, which set of parentheses is evaluated first
in an arithmetic expression? ______________.
c) A location in the computer’s memory that may contain different values at
various times throughout the execution of a program is called a_________.
Division and modulus
The inner one
Variable
إذا أردت أن يحبك : خالصة الكالم
.الناس، ازهد فيما بين أيديمم
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Exercise 1.19: What, if anything, prints when each of the following C++
statements is performed? If nothing prints, then answer "nothing".
Assume x = 2 and y = 3.
a) cout << x; 2
b) cout << x + x; 4
c) cout << "x = "; x =
d) cout << "x = " << x; x = 2
e) cout << x + y << " = " << y + x; 5 = 5
f) z = x + y; nothing
g) cin >> x >> y; nothing
h) // cout << "x + y = " << x + y; nothing
i) cout << "\n"; a new line
Statement Output
صوت من شكر معروفك أجمل
من تغريد الطيور، فال تبخل به
.لى من صنع لك معروفاع
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Exercise 1.21: Given the algebraic equation y = ax3 + 7, which of the
following, if any, are correct C++ statements for this equation?
a) y = a * x * x * x + 7;
b) y = a * x * x * ( x + 7 );
c) y = ( a * x ) * x * ( x + 7 );
d) y = ( a * x ) * x * x + 7;
e) y = a * ( x * x * x ) + 7;
f) y = a * x * ( x * x + 7 );
قد ه يحول ضميرك بين وقوعك في ظلم أحد،
.لكن دعه يحولك من أن تتلذذ بمذا الظلم
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Exercise 1.26: Write a program that inputs three integers from the
keyboard and prints the sum, average, product, smallest and largest of these
numbers. The screen dialogue should appear as follows:
# include <iostream>
using namespace std;
int main ( )
{
int x, y, z, smallest, largest;
cout << "Input three different integers: ";
cin >> x >> y >> z;
cout << "Sum is " << x + y + z << endl;
cout << "Average is " << ( x + y + z ) / 3 << endl;
cout << "Product is " << x * y * z << endl;
smallest = x;
if ( y < smallest )
smallest = y;
if ( z < smallest )
smallest = z;
cout << "Smallest is " << smallest << endl;
largest = x;
if ( y > largest )
largest = y;
if ( z > largest )
largest = z;
cout << "Largest is " << largest << endl;
return 0;
}
Input three different integers: 13 27 14
Sum is 54
Average is 18
Product is 4914
Smallest is 13
Largest is 27
بالكتاب تم تأخير( 1)بشابتر
(2)لشابتر doubleشرح
قمووة الكوورم تتمثوول فووي فعوول معووروف
لشخص لون يعورف أنوك فعلوت ذلوك،
.أو لشخص لن يستطع رده لك
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Exercise 1.29: What does the following code print?
cout << "*\n**\n***\n****\n*****\n";
*
**
***
****
*****
Exercise 1.31: Write a program that reads an integer and determines and
prints whether it is odd or even.
(Hint: Use the modulus operator. An even number is a multiple of two.
Any multiple of two leaves a remainder of zero when divided by 2).
# include <iostream>
using namespace std;
int main ( )
{
int n;
cout << "Enter an integer: ";
cin >> n;
if ( n % 2 == 0 )
cout << n << " is even" << endl;
if ( n % 2 != 0 )
cout << n << " is odd" << endl;
return 0;
}
Enter an integer: 4
4 is even
Enter an integer: 15
15 is odd
يكون ( 0) على أي رقم زوجيباقي تقسيم
.(-1)أو ( 1)فيكون صفر بخالف الفردي
ه تستح من إعطاء القليل
.فإن الحرمان أقل منه
May 2014
بالبريد اإللكترونيأو 9 4444 062 برسالة نصيةتراها ضرورية مالحظات أوأي خطأ باإلبالغ عن المساهمةالنوتات مجانية للنفع العام فيرجى
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
neths.-eng, comhs.-eng بالموقعين مجانا شرح ومسائل محلولة @hs.com-enginfo 9 4444 260 دة شعبانحما. م
Exercise 1.32: Write a program that reads in two integers and determines
and prints if the first is a multiple of the second.
(Hint: Use the modulus operator).
# include <iostream>
using namespace std;
int main ( )
{
int x, y;
cout << "Enter two integers: " ;
cin >> x >> y;
if ( x % y == 0 )
cout << x << " is a multiple of " << y << endl;
if ( x % y != 0 )
cout << x << " is not a multiple of " << y << endl;
return 0;
}
Enter two integers: 12 3
12 is a multiple of 3
Enter two integers: 20 7
20 is not a multiple of 7
إذاآلخر ا رقم مضاعفاليكون
.كان باقي نات التقسيم صفرا
مر ه تصنعن لنفسك معبرا في الن
.ثم تجاهد بعد ذلك لتجمع أجره
top related