امثله على ماسبق من الدروس

الامثلة:


للتبديل بين قيم متغيرين نحن بحاجه الى متغير ثالث  كما في المثال :



 #include <iostream>

#include <string>

using namespace std ;


void main ()

{ int x=50,y=10; int t;

cout<<"x="<<x<<"y="<<y<<endl;

t=x; x=y; y=t;

cout<<"x="<<x<<"y="<<y<<endl;

system("pause");  }



 برنامج يطبع فاتوره حيث يدخل اسم الموظف و عدد ساعات العمل في اليوم  يطبع البرنامج الاسم وعدد ساعات العمل في الشهر  و الراتب    و مقدار خصم الضريبه و قيمه الراتب بعد الضريبه  علما بان عدد ايام الدوام الفعلي 22يوم في الشهر   و الساعه ب20$ دولار   والضريبه  0.06 %  







 #include <iostream>

#include <string>

using namespace std ;
void main (){
string name ;

float work_hours,

 work_hours_in_month,   salary,       tax,     after_tax ;

cout<<"enter the name: \t";

cin >> name;cout<<" \n enter the work hours:\t";

cin >> work_hours;
work_hours_in_month = work_hours*22;salary=work_hours_in_month * 20 ;

tax = salary * 0.06;after_tax =salary-tax;

cout<<"\n*****************************\n";

cout<<"Employee Name:"<<name <<endl;

cout<<"Number of working hours this month:"<<work_hours_in_month <<endl;

cout<<"Timepiece price: $ 20" <<endl;

cout<<"Total salary:"<<salary <<endl;

cout<<"Amount of tax deduction:"<<tax <<endl;

 cout<<"net salary:"<<after_tax <<endl;

cout<<"\n*****************************\n";


system("pause"); 

 }








المستخدم يدخل اسم الطالب و 10 علامات له :البرنامج يقوم بحساب المعدل وايجاد اصغر علامه واكبر علامه ثم يطبع المعدل واصغر علامه واكبر علامه و ناجح اذا كان المعدل اكبر من 50  غير ذلك يطبع راسب او F




 #include <iostream>
#include <string>
using namespace std ;

void main (){

string name ;
float x1,x2,x3,x4,x5,x6,x7,x8,x9,x10   , avg  , min ,max ;
cout<<"name ::  ";
cin>> name;
cout<<"10 mark:\n";
cin>>x1>>x2>>x3>>x4>>x5>>x6>>x7>>x8>>x9>>x10;
avg=(x1+x2+x3+x4+x5+x6+x7+x8+x9+x10)/10;
         min=x1;        max=x1;
//*****min
if (min>x2)
min=x2;
 if (min>x3)
min=x3;
 if (min>x4)
min=x4;
 if (min>x5)
min=x5;
 if (min>x6)
min=x6;
 if (min>x7)
min=x7;
 if (min>x8)
min=x8;
 if (min>x9)
min=x9;
 if (min>x10)
min=x10;

 //*********************max 
 if (max<x2)
max=x2;
  if (max<x3)
max=x3;
   if (max<x4)
max=x4;
    if (max<x5)
max=x5;
if (max<x6)
max=x6;
 if (max<x7)
max=x7;
  if (max<x8)
max=x8;
   if (max<x9)
max=x9;
if (max<x10)
max=x10;


cout<<"avg="<<avg<<" \n min="<<min<<"\n max= "<<max<<endl;
if (avg>=50)
cout<<"pass"<<endl;
else 
cout<<"F"<<endl;
system("pause");  }








المثال السابق اجعل عمليه الادخال10 مرات اي ينفذ البرنامج ل 10 طلاب باستخدام جمله FOR








 #include <iostream>

#include <string>

using namespace std ;


void main ()

{

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

{string name ;

float x1,x2,x3,x4,x5,x6,x7,x8,x9,x10   , avg  , min ,max ;

cout<<"name ::  ";cin>> name;cout<<"10 mark:\n";

cin>>x1>>x2>>x3>>x4>>x5>>x6>>x7>>x8>>x9>>x10;

avg=(x1+x2+x3+x4+x5+x6+x7+x8+x9+x10)/10; 

        min=x1;        max=x1;  

//*****min

if (min>x2) min=x2;

 if (min>x3) min=x3;

 if (min>x4) min=x4;

 if (min>x5) min=x5; 

if (min>x6) min=x6; 

if (min>x7) min=x7; 

if (min>x8) min=x8; i

f (min>x9) min=x9; 

f (min>x10) min=x10;


 //*********************max  

if (max<x2) max=x2; 

 if (max<x3) max=x3;

   if (max<x4) max=x4; 

   if (max<x5) max=x5;

if (max<x6) max=x6;  

 if (max<x7) max=x7;  

 if (max<x8) max=x8;  

   if (max<x9) max=x9;

if (max<x10) max=x10;

cout<<"avg="<<avg<<" \n min="<<min<<"\n max= "<<max<<endl;

if (avg>=50) cout<<"pass"<<endl;

else  cout<<"F"<<endl;

} system("pause"); 

 }

رابط الحلقه اضغط هنا

Comments

Popular posts from this blog

الدرس التاسع 9: الفنكشن function تعريفه وانواعه

الدرس السابع 7: جمله الشرط Switch في لغه c++

الدرس الثالث عشر 13: القيمه العشوائيه rund في c++