مختبر 8
3 مشترك
صفحة 1 من اصل 1
مختبر 8
السلام عليكم
ازا في أي خطأ بالحل خبروني..
وازا في حلول تانية شاركونا
^___^
..
هاي اسئلة مختبر يوم الاثنين بس اللي كاتب نص الأسئلة يكتبها لأنو انا مش كاتبها
بس هيك فكرة السؤال
هاي اسئلة مختبر يوم الاثنين بس اللي كاتب نص الأسئلة يكتبها لأنو انا مش كاتبها
بس هيك فكرة السؤال
السؤال الاول: عرف مصفوفة من حجم 10 واسند لها قيم، ثم من خلال دالة اعكس قيم المصفوفة (دون استخدام مصفوفة اخرى) واطبع الناتج في دالة ثانية
- الكود:
#include <iostream>
#define size 10
using namespace std;
void swap();
void prn();
int Num[size];
int main(){
for (int i=0;i<size;i++)
cin>>Num[i];
swap();
cout<<endl;
system("pause");
}
void swap(){
int temp;
for(int i=0;i<(size/2);i++)
{
temp=Num[i];
Num[i]=Num[size-1-i];
Num[size-1-i]=temp;}
prn();
}
void prn(){
cout<<"the arr is ";
for(int i=0;i<size;i++){
cout<<Num[i]<<" ";}
}
السؤال الثاني:استخدم دالة مناسبة لحساب عدد حروف العلة في جملة يدخلها المستخدم
- الكود:
#include <iostream>
#include <string>
using namespace std;
void vowelCounter(string sentence);
int main(){
string sentence = "";
cout<<"enter a sentence: ";
getline(cin,sentence);
vowelCounter(sentence);
cout<<endl;
system("pause");
}
void vowelCounter(string sentence){
int voil=0;
for(int w=0; w < sentence.length() ;w++)
switch(sentence[w]){
case 'a': case 'e': case 'o': case 'u': case 'i': voil++;break;
}
cout<<"the number of voils= "<<voil;
}
السؤال الثالث: اكتب برنامج لفحص ما اذا كانت الكلمة المدخلة متماثلة حول الخانة الوسطى ام لا (مثل aammbbmmaa متماثل)
- الكود:
#include <iostream>
#include <string>
#define size 100
using namespace std;
int swap(char sentence[size]);
char sentence[size],test[size];
int main(){
int decision;
cout<<"type anything: ";
cin>>sentence;
strcpy(test,sentence);
decision=swap(sentence);
if(decision==0)cout<<"palindrome ";
else cout<<"not palindrome ";
cout<<endl;
system("pause");
}
int swap(char sentence[size]){
char temp;
int size2,decision;
size2=strlen(sentence);
for(int i=0;i<(size2/2);i++)
{
temp= sentence[i];
sentence[i]=sentence[size2-1-i];
sentence[size2-1-i]=temp;}
decision=strcmp(test,sentence);
return decision;
}
ازا في أي خطأ بالحل خبروني..
وازا في حلول تانية شاركونا
^___^
عدل سابقا من قبل Basel Tamimi في 27/4/2011, 1:16 pm عدل 1 مرات
رد: مختبر 8
Basel Tamimi كتب:
السؤال الاول: read 10 integers into array A[10] and them do:
call afunction reserve to reserve the elements of the array .
call afunction preserve to print the elements of the new array.
- الكود:
#include <iostream>
#define size 10
using namespace std;
void swap();
void prn();
int Num[size];
int main(){
for (int i=0;i<size;i++)
cin>>Num[i];
swap();
cout<<endl;
system("pause");
}
void swap(){
int temp;
for(int i=0;i<(size/2);i++)
{
temp=Num[i];
Num[i]=Num[size-1-i];
Num[size-1-i]=temp;}
prn();
}
void prn(){
cout<<"the arr is ";
for(int i=0;i<size;i++){
cout<<Num[i]<<" ";}
}السؤال الثاني:استخدم دالة مناسبة لحساب عدد حروف العلة في جملة يدخلها المستخدم
- الكود:
#include <iostream>
#include <string>
using namespace std;
void vowelCounter(string sentence);
int main(){
string sentence = "";
cout<<"enter a sentence: ";
getline(cin,sentence);
vowelCounter(sentence);
cout<<endl;
system("pause");
}
void vowelCounter(string sentence){
int voil=0;
for(int w=0; w < sentence.length() ;w++)
switch(sentence[w]){
case 'a': case 'e': case 'o': case 'u': case 'i': voil++;break;
}
cout<<"the number of voils= "<<voil;
}السؤال الثالث: write aprogram to read astring and then calls afunction pal to check if the string is palindrome or not.
- الكود:
#include <iostream>
#include <string>
#define size 100
using namespace std;
int swap(char sentence[size]);
char sentence[size],test[size];
int main(){
int decision;
cout<<"type anything: ";
cin>>sentence;
strcpy(test,sentence);
decision=swap(sentence);
if(decision==0)cout<<"palindrome ";
else cout<<"not palindrome ";
cout<<endl;
system("pause");
}
int swap(char sentence[size]){
char temp;
int size2,decision;
size2=strlen(sentence);
for(int i=0;i<(size2/2);i++)
{
temp= sentence[i];
sentence[i]=sentence[size2-1-i];
sentence[size2-1-i]=temp;}
decision=strcmp(test,sentence);
return decision;
}
aya- عدد المساهمات : 4
تاريخ التسجيل : 18/04/2011
صفحة 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