مختبر 9
3 مشترك
صفحة 1 من اصل 1
مختبر 9
السؤال الاول: اكتبر برنامج يقوم بتعريف مصفوفة 4*4 واستدعاء الfunctions كما يلي:
Fill // Sum // Squere // print
solution
- الكود:
#include <iostream>
using namespace std;
void Fill(int Array[4][4]){
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
cin>>Array[i][j];
}
int Sum(int Array[4][4]){
int sum=0;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
sum=sum+Array[i][j];
return sum;
}
void Square(int Array[4][4]){
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
Array[i][j]*=Array[i][j];
}
void Print(int Array[4][4]){
for(int i=0;i<4;i++){
for(int j=0;j<4;j++)
cout<<Array[i][j]<<" ";
cout<<endl;}
}
void main(){
int Array[4][4],total;
cout<<"fill the array:\n";
Fill(Array);
total=Sum(Array);
Square(Array);
cout<<"the sum is "<<total<<endl;
Print(Array);
cout<<endl;
system("pause");
}
الفرع الاول:السؤال الثني: كما في ورقة الpointers
- الكود:
#include <iostream>
using namespace std;
int main(){
int firstvalue, secondvalue;
int *mypointer;
mypointer=&firstvalue;
*mypointer=10;
mypointer=&secondvalue;
*mypointer=20;
cout<<"firstvalue is "<<firstvalue<<endl;
cout<<"secondvalue is "<<secondvalue<<endl;
cout<<endl;
system("pause");
return 0;
}
الفرع الثاني:
- الكود:
#include <iostream>
using namespace std;
int main(){
int firstvalue =5,secondvalue=15;
int *p1=new(int),*p2=new(int);
p1=&firstvalue;
p2=&secondvalue;
*p1=10;
*p2=*p1;
p1=p2;
*p1=20;
cout<<"firstvale is "<<firstvalue<<endl;
cout<<"secondvalue is "<<secondvalue<<endl;
cout<<endl;
system("pause");
return 0;
}
السؤال الثالث: كما في ورقة الfile
- الكود:
#include <iostream>
#include <istream>
#include <fstream>
using namespace std;
int main(){
int w;char*name;
ofstream fout ("c:\\students\\ff.txt");
ifstream fin("c:\\students\\fff.txt");
int age;int avg; char L;
cout<<"\n enter your name "; gets (name);
cout<<"\n enter your average "; cin>>avg;
if (fout== NULL){
cout<<endl<<"==============no";
system ("pause");exit (0);}
switch(avg/10){
case 6: L='D';break;
case 7: L='C';break;
case 8: L='B';break;
case 9: L='A';break;
default: L='F';
}
fout<<"\n my name is: "<<name<<"\n my avg is: "<<avg<<" = "<<L;
fin>>age;
cout<<"\n my age is: "<<age<<" years old";
fout<<"\n my age is: "<<age<<" years old";
cout<<endl;
system("pause");
return 0;
}
لا تنسى ان تضيف الملفين ff و fff وادخال قيمة في الملف الاول في نفس الموقع المدرج ضمن الحل
صفحة 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