ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى


انضم إلى المنتدى ، فالأمر سريع وسهل

ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى
ملتقى البرمجة
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

مختبر 7

2 مشترك

اذهب الى الأسفل

تثبيت مختبر 7

مُساهمة من طرف Basel Tamimi 22/4/2011, 11:39 am

// C++ programming
// All function lab examples:
// By:Basel y. Tamimi
// --------------------------


Q1))do a swap using function (applied by call by reference)

الكود:

#include <iostream>
void swap(int &x,int &y);
using namespace std;
void main(){
   
   int x,y;
   cout<<"enter two integers num: ";
cin>>x>>y;
cout<<"Befor:\n";
cout<<"x= "<<x<<" y= "<<y;

swap (x,y);

cout<<endl<<endl;
cout<<"After:\n";
cout<<"x= "<<x<<" y= "<<y;

cout<<endl;
system ("pause");
}

void swap (int &x, int &y){
int temp;
temp=x;
x=y;
y=temp;

}


Q2)) enter 3 char. and the program should rearrange them and print the result in main function


الكود:

#include <iostream>
void order(char &x,char &y,char &z);
using namespace std;
void main(){
char x,y,z;
   cout<<"enter 3 characters: ";
   cin>>x>>y>>z;

order(x,y,z);
   
cout<<"the order is "<<x<<" "<<y<<" "<<z;
cout<<endl;
system ("pause");
}

void order(char &x,char &y,char &z){
   char max,min,middle;

   //for comparing
   if(x>y){
max=x;
min=y;
if(z>x){
max=z;
middle=x;}
else if (z<y)
{min=z;
middle=y;}
else middle=z;
   }
   else if (x<y){
max=y;
min=x;
if(z>y){
max=z;
middle=y;}
else if (z<x)
{min=z;
middle=x;}
else middle=z;}

x=min;
y=middle;
z=max;

}


عدل سابقا من قبل Basel Tamimi في 27/4/2011, 1:18 pm عدل 1 مرات
Basel Tamimi
Basel Tamimi

عدد المساهمات : 44
تاريخ التسجيل : 09/03/2011
العمر : 32
الموقع : الخليل

https://is-it1.alafdal.net/

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تثبيت رد: مختبر 7

مُساهمة من طرف Basel Tamimi 22/4/2011, 11:42 am

Q3)) build a program that calculate exact time period from start time and end time and print the result in main function
conditions:1)its a time so it would take a max as 23:59:59 and at least 00:00:00.
2)the end time should be greater than the first time.


الكود:

#include <iostream>
void time(int &h,int &m,int &s);
using namespace std;
void main(){

int h1,m1,s1;
cout<<"enter the first time as (hh mm ss): ";
cin>>h1>>m1>>s1;

if(h1>23 || h1<0 || m1>59 || m1<0 || s1>59 || s1<0)
   cout<<"\n"<<"error";
else{
time( h1, m1, s1);

cout<<"the exact time = "<<h1<<" hours "<<m1<<" minutes "<<s1<<" seconds";
}


cout<<endl;
system ("pause");
}

void time(int &h,int &m,int &s){
int h2,m2,s2,totalh,totalm,totals;

cout<<"enter the end time as (hh mm ss): ";
cin>>h2>>m2>>s2;

if(h2>23 || h2<0 || m2>59 || m2<0 || s2>59 || s2<0){
   cout<<"\n"<<"error\n";
s=0;m=0;h=0;}

else{
if(s2<s){
s2=s2+60;
m2=m2-1;
}

if(m2<m){
m2=m2+60;
h2=h2-1;}

totals=s2-s;
totalm=m2-m;
totalh=h2-h;
s=totals;
m=totalm;
h=totalh;
}
}
Basel Tamimi
Basel Tamimi

عدد المساهمات : 44
تاريخ التسجيل : 09/03/2011
العمر : 32
الموقع : الخليل

https://is-it1.alafdal.net/

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تثبيت رد: مختبر 7

مُساهمة من طرف Basel Tamimi 22/4/2011, 11:44 am

ملاحظة أخيرة:


هناك اكثر من طريقة لحل الأسئلة.

واللي عندو طريقة اسهل ينزلها ^__^
Basel Tamimi
Basel Tamimi

عدد المساهمات : 44
تاريخ التسجيل : 09/03/2011
العمر : 32
الموقع : الخليل

https://is-it1.alafdal.net/

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تثبيت رد: مختبر 7

مُساهمة من طرف anas mohtaseb 22/4/2011, 12:11 pm

الله يجعلهم يسلمو اديك ويرضى عليك يا رب


Basel Tamimi كتب:ملاحظة أخيرة:


هناك اكثر من طريقة لحل الأسئلة.

واللي عندو طريقة اسهل ينزلها ^__^

ان شاء الله رح انزلهم
بس والله انبلشت بالاسايمنت دورتني مع انو الاسالة مش كتير صعبة بس عجبو علي شوي
anas mohtaseb
anas mohtaseb

عدد المساهمات : 29
تاريخ التسجيل : 08/03/2011
الموقع : https://www.facebook.com/anasmohtaseb

https://www.facebook.com/anasmohtaseb

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تثبيت رد: مختبر 7

مُساهمة من طرف Basel Tamimi 22/4/2011, 12:36 pm

امممممممم يمكن اصعب اشي السؤال الأول والأخير


على كلن انت سلمتها صح؟؟
انا خلصتهم امبارح وسلمتهم اليوم بس على قولتك عجبو علي شوي

^__^
Basel Tamimi
Basel Tamimi

عدد المساهمات : 44
تاريخ التسجيل : 09/03/2011
العمر : 32
الموقع : الخليل

https://is-it1.alafdal.net/

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تثبيت رد: مختبر 7

مُساهمة من طرف anas mohtaseb 22/4/2011, 4:20 pm

السؤال الاول اسهل اشي ^ح^
anas mohtaseb
anas mohtaseb

عدد المساهمات : 29
تاريخ التسجيل : 08/03/2011
الموقع : https://www.facebook.com/anasmohtaseb

https://www.facebook.com/anasmohtaseb

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

- مواضيع مماثلة

 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى