مختبر 7
2 مشترك
صفحة 1 من اصل 1
مختبر 7
// C++ programming
// All function lab examples:
// By:Basel y. Tamimi
// --------------------------
Q1))do a swap using function (applied by call by reference)
Q2)) enter 3 char. and the program should rearrange them and print the result in main function
- الكود:
#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 مرات
رد: مختبر 7
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.
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;
}
}
رد: مختبر 7
الله يجعلهم يسلمو اديك ويرضى عليك يا رب
ان شاء الله رح انزلهم
بس والله انبلشت بالاسايمنت دورتني مع انو الاسالة مش كتير صعبة بس عجبو علي شوي
Basel Tamimi كتب:ملاحظة أخيرة:
هناك اكثر من طريقة لحل الأسئلة.
واللي عندو طريقة اسهل ينزلها ^__^
ان شاء الله رح انزلهم
بس والله انبلشت بالاسايمنت دورتني مع انو الاسالة مش كتير صعبة بس عجبو علي شوي
رد: مختبر 7
امممممممم يمكن اصعب اشي السؤال الأول والأخير
على كلن انت سلمتها صح؟؟
انا خلصتهم امبارح وسلمتهم اليوم بس على قولتك عجبو علي شوي
^__^
على كلن انت سلمتها صح؟؟
انا خلصتهم امبارح وسلمتهم اليوم بس على قولتك عجبو علي شوي
^__^
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
3/7/2011, 11:05 pm من طرف anas mohtaseb
» امتحان الفاينال لمختبر برمجة الحاسوب
26/5/2011, 1:45 pm من طرف Basel Tamimi
» حل سؤال الموظفين والرواتب
22/5/2011, 3:17 pm من طرف Basel Tamimi
» sum program with parameters
22/5/2011, 9:33 am من طرف Basel Tamimi
» مختبر 9
18/5/2011, 5:43 pm من طرف Basel Tamimi
» سلايدات الكتاب للاقسام 4 5 7
6/5/2011, 2:07 pm من طرف Basel Tamimi
» شكرا لكم
4/5/2011, 8:51 pm من طرف anas mohtaseb
» Programming Assignment الحل الثاني
2/5/2011, 7:58 am من طرف Basel Tamimi
» سؤال على ال parallel arrays
1/5/2011, 5:06 am من طرف Basel Tamimi