موقع طلبة جامعة البحرين

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

تسجيل دخول
  • قسم المكتبة الجامعية مغلق مؤقتا بعد الاستهداف التي تعرضت له بعض خدمات أمازون في البحرين، جاري استرجاع الملفات ونقلها إلى سيرفرات جديدة وسيتم بعدها اعادة افتتاح المكتبة

ITCS112 - ITCS104 - ITCS102 للفصل الصيفي 2014 - 2015

في احد في سكشن دكتورة مياده !
كلما اجرب في الاكواد الي تعطينا اياها اجوف فيه معضله :RpS_huh:


السؤال الي يحذف ال vowels
حلته ويانا جذي ,
كود:
[B][SIZE=2]#include <iostream>[/SIZE][/B][COLOR=#000000][B][SIZE=2]
#include <string>[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]using namespace std;[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]int main ()[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]{[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    string oldstring,newstring;[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    int i;[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    string ch;[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]
[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    cout<<"enter string ";[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    cin>>oldstring;[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    for ( i=0;i<oldstring.length();i++)[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    {[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]        ch=tolower(oldstring[i]);[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]        if ( ch!="e"||ch !="a"||ch!="o"||ch!="u"||ch!="i")[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]            newstring+=oldstring[i];[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]
[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    }[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    cout<<"new string after removing vowels = " <<newstring<<endl;    [/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]    return 0;[/SIZE][/B][/COLOR]
[COLOR=#000000][B][SIZE=2]}[/SIZE][/B][/COLOR]


:RpS_huh:
مايحذف شي , ولا يتغير شي !


السالفة ومافيها لازم تخلون بدل " || " تحطون " && " ..
اعتقد جذي ماجربت ..
:whistling:
 
بالنسبة لحلك تقدر تسويه جذي :nosweat: ..

كود:
int count(string x, string y){
    int c=0;
    for(int i=0; i<=y.size(); i++){
        if(y.find(x,i+1)!=y.find(x,i))c++;
    }
    return c;
}
تشكر ، توني داري لأن إذا أبغي قيمة خطأ أحط =! >>> كنت أحط مثلا جدي num==num! من جدي يطلع لي خطأ
​
 

و انا أقول ويش صاير و ليش يطلع عندي خطأ .. المفروض الناتج 3 مو 2
طلع سؤالش أمواج خطأ ، ليش تسوين فينا جدي ... خليتيني أتحطّم تحطيم !!

المهم هذا حليّ :smile2:

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

int count(string x, string y){
    int c=0;
    for(int i=0; i<=y.size(); i++){
        if(y.find(x,i+1)==y.find(x,i)){}
        else{c++;}
    }
    return c;
}
int main(){
    string str1,str2;
    cout<<"Enter a word: "; cin>>str1;
    cout<<"Enter a sentence: "; getline(cin,str2);
    cout<<"Number of ("<<str1<<"): " <<count(str1,str2);
    return 0;
}

اذا طلع لك صح الاجابة و اشتغل عدل البرنامج أتوقع صح

احنا حليناه بطريقة غير عن هذي بعد ( بالوايل لوب )

+ آسفة على الخطأ بالسؤال

كود:
[LEFT]
#include<iostream>
#include<string>
using namespace std;
int count(string x,string y)
{
    int pos=0;
    int counter=0;
    while(y.find(x,pos)!=string::npos)
    {
        pos= y.find(x,pos);
        counter++;
        pos+=1;    
    }
    return counter;
}
void main()
{
    string x,y;


    cout<<"Enter Enter a string x: "<<endl;
     getline(cin,x); cout<<endl;
    cout<<"Enter Enter a string y: "<<endl;
    getline(cin,y); cout<<endl;
    
    cout<<" No. of"<<x<<" = "<<count(x,y);


}



[/LEFT]
 
اذا ممكن حل هالسؤالين ..

1- write a program that asks the user to enter a string then change all vowels to capital and output the string on screen


2- writ a program that reads 20 names from file names "name.txt" your program should find the size of all 20 name to file "lenght.txt" and output the maimum name size on screen
 
اذا ممكن حل هالسؤالين ..

1- write a program that asks the user to enter a string then change all vowels to capital and output the string on screen


2- writ a program that reads 20 names from file names "name.txt" your program should find the size of all 20 name to file "lenght.txt" and output the maimum name size on screen

1 =>

كود:
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string str;
    cout<<"Enter your string :\n";
    getline(cin,str);
    for(int i=0;i<str.size();i++)
    {
        if (str[i]=='i')str[i]='I';
        else if (str[i]=='o')str[i]='O';
        else if (str[i]=='u')str[i]='U';
        else if (str[i]=='e')str[i]='E';
        else if (str[i]=='a')str[i]='A';
    }
    cout<<endl<<"Your string after change :\n"<<str<<endl;
    system("pause");
    return 0;
}
2 =>

كود:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
    string str;
    int min=100;
    ifstream in;in.open("name.txt");
    ofstream out;out.open("length.txt");
    if (!in){cout<<"Erorr no file";return 1;}
    while(!in.eof())
    {
        in>>str;
        out<<str.length()<<endl;
        if (str.length()<min)min=str.length();
    }
    cout<<"Maimum name size : "<<min<<endl;
    system("pause");
    return 0;
}
 
اذا ممكن حل هالسؤالين ..

1- write a program that asks the user to enter a string then change all vowels to capital and output the string on screen


2- writ a program that reads 20 names from file names "name.txt" your program should find the size of all 20 name to file "lenght.txt" and output the maimum name size on screen
الأخ noise ما قصّر ، و إن شاء الله يكون حله مفهوم إليك ... و بالتوفيق :smile2:
​
 
متى يصير المدتيرم ؟؟!..
 
مسألة البحث عن فاول في الكلمة من جديد :RpS_tongue: << مصرة اتحله بالفنكشنات بطريقتها :shiny:
لان الدكتور يبي حلنا باجر و ما اعرف آخذ حل جاهز :nosweat:

أحد يقدر يشوف وين الخلل :/

ماكو ايرورات لكن النتيجة غلط .. ما يتغير شي بالكلمة بس تتكرر *_*

كود:
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    string word;
    string vowel="aAeEiIoOuU";
    int num=0;
    int pos=0;


    cout<<"Enter a word ";
    getline(cin,str);


    while(pos!=string::npos)
    {
        for(int i=0; i<vowel.length(); i++)
            pos= str.find(vowel[i]);
        
        word+=str.substr(num,pos-num);
        num=pos+1;
    }


    word+=str.substr(num,str.length()-num);


    cout<<"The word: "<<word;


    return 0;


}
 
مسألة البحث عن فاول في الكلمة من جديد :RpS_tongue: << مصرة اتحله بالفنكشنات بطريقتها :shiny:
لان الدكتور يبي حلنا باجر و ما اعرف آخذ حل جاهز :nosweat:

أحد يقدر يشوف وين الخلل :/

ماكو ايرورات لكن النتيجة غلط .. ما يتغير شي بالكلمة بس تتكرر *_*

كود:
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    string word;
    string vowel="aAeEiIoOuU";
    int num=0;
    int pos=0;


    cout<<"Enter a word ";
    getline(cin,str);


    while(pos!=string::npos)
    {
        for(int i=0; i<vowel.length(); i++)
            pos= str.find(vowel[i]);
        
        word+=str.substr(num,pos-num);
        num=pos+1;
    }


    word+=str.substr(num,str.length()-num);


    cout<<"The word: "<<word;


    return 0;


}
string::npos تستخدم حق الـstrings للتأكد إذا مثلاً إذا وصل لنهاية الـstring أو لا
قيمتها ثابته (-1)
عندج شرط الـwhile loop خطأ لأنج قاعدة تقارنين رقم المتغير pos بـ-1
يصير كأنج كاتبة
PHP:
pos!=-1
المفترض تقارنين متغير من نوع string
مثلاً
PHP:
str[i]!=string::npos


والـfor loop
انتي قاعدة تغيرين قيمة الـpos كل مرة، لين ما توصل قيمة الـi لطول المتغير vowel اللي هو 10
يعني انتي كأنج تبحثين عن آخر حرف vowel بالمتغير str، المفروض العكس.


PHP:
pos= str.find(vowel[i]);
مادري بالضبط شنو المشكلة هنيه، لكنه يرجع القيمة -1
وبما أنه برجع -1 اللي بعده مباشرة يكون خطأ، اقصد هنيه
PHP:
word+=str.substr(num,pos-num);
لأن العملية الحسابية بتكون خطأ ايضاً


وهنيه
PHP:
num=pos+1;
بما انج تستخدمين المتغير num بالـsubstr
تحتاجين تتأكدين أنه str[num] ما راح يكون vowel


الطريقة اللي فكرتي فيها بالحل شوي معقدة وتعتمد على اشياء محدودة، فتحتاجين شروط وايد بالحل وراح ياخذ وقت عشان تفكرين فيهم
حاولت احله بالطريقة اللي تفكرين فيها بس ما قدرت.
 
^ مشكور اخوي
هذا حل ثاني اول شي طلع قيمة غلط بعدين صار ايرور
الخلل في انه فور لوب داخل فور لوب يعني اذا قارن لازم كذا مرة للحرف الواحد بيتحقق الشرط حتى لو كان فاول بينطبع
فكرت بشرط أو طريقة لتفادي هالسالفة ما وصلت لنتيجة
و شكله هذا الحل معقد أزيد من الأول << شكلي أحب التعقيد :RpS_huh::nosweat:
​
كود:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string word1,word2;
int num=0;
string v="aAeEiIoOuU";
cout<<"Enter the word ";
getline(cin,word1);
for(int i=0;i<word1.length();i++)
{
for(int j=0;j<v.length();j++)
{
if(word1[i]==v[j])
{
	word2+=word1.substr(i,1);
	
}
	
cout<<"The new word is"<<word2;
return 0;
}
 
ما خلصتون جبتر 8 ؟ :nosweat:

ابتدينا في جبتر 10.. اذا عندكم اسئلة حطوها :RpS_tongue:
 
Searching in array

بالنسبة للبحث في الarray
نفرض ان عندنا array و فيها 10 ارقام
ونبي نبحث عن قيمة معينه ونبي نعرف وين تكون يعني في اي cell بالضبط
هذي فكرة الserching وهي مهمه طبعاً

للتوضيح اكثر كتبت الكود بأعتبار ان عندنا array و فيها 10 عناصر
يعني عطيت الarray قيم ابتدائية
المفروض ما اكتب القيم يعني عشان اوضح كيف نتعامل معاه بشكل عام بس هي ماراح تفرق وايد

PHP:
#include <iostream>
using namespace std;
int main()
{
    
      int  array[10]={10,20,30,40,50,60,70,80,90,80} , key , index;
      bool found = false ;  
         
      cout<< "Enter the number you want to find = "<<endl;
      cin>> key; 
      
      for(int i=0; i<10; i++)    
       {
            if (array[i] == key)   // if number is found
           {
                   found = true;  
                   index=i; // index = i , to use(index) later .
                   break ;    // break out of for loop
            }
        }
        
      if (found)
      cout<< "Your number is at " << index <<".\n";
       else
       cout<< "Sorry,Your number is not in array"<<endl;
    
      system("pause");
     return 0;
}

هذا نفس الكود اللي فوق بالضبط بس سويته function

PHP:
#include <iostream>
using namespace std;
void searchfun(int array[10], int key2)
    {
    int index;
    bool found = false ;  
    for(int i=0; i<10; i++)    
       {if (array[i] == key2)
           {found = true;  
           index=i; 
           break ;    
            }
        }
      if (found)
      cout<< "Your number is at " << index <<".\n";
      else
      cout<< "Sorry,Your number is not in array"<<".\n";  
         }
         
int main()
{   
      int  array[10]={10,20,30,40,50,60,70,80,90,80} , key ;
      cout<< "Enter the number you want to find = "<<endl;
      cin>> key; 
  
   searchfun(array, key);
   
    system("pause");
     return 0;
}

في شغله بعد ، لو بغيت ابحث في الarray عدد لانهائي من المرات
يعني وقت اللي حبيت يوقف البرنامج مثلا اكتب (-1)
اذا تذكرون كنا نستخدم while loop
في الكود اللي كتبته فوق
محتاج اضيف الشرط التالي

PHP:
while(key!=-1)

عشان يستمر يعمل لين انا اكتب -1 واوقفه

بس ماراح اكتب الكود انا ، اللي يحب يطبق يسويه ، ويحطه لنا نشوفه
:smile2:


اعتذر على أي تقصير
نسألكم الدعاء
هذا شرح اول درس في جبتر 10 > sequential search

<< من المواضيع السابقة.. شرحITCS Student
 
Write a program to change all occurence of item to -100

write a program to count all occurence of item in list

بغيت الحل مع الشرح اذا ماعليكم امر :no::RpS_blink:
جبتر ١٠
 
Write a program to change all occurence of item to -100

write a program to count all occurence of item in list

بغيت الحل مع الشرح اذا ماعليكم امر :no::RpS_blink:
جبتر ١٠

السؤال الأول
افرض عندنا array فيها 10 ارقام وقد يكون فيها ارقام متكرره يعني مثلا رقم 10 متكرر ثلاث مرات
المطلوب نطلب من اليوزر يدخل رقم معين (item) ونفرض يكون الرقم اللي دخلناه 10
ف بقوم يبدل 10 الى -100
في كل مره يشوفها في list او array


الحل ( طبعاً سويته بسيط كلش بس عشان تشوف الفكرة )

PHP:
#include<iostream>
using namespace std;
int main(){
    
    int list[10]={10,25,10,4,8,7,6,7,9,10};
    int item;

cout<<"Enter item : "<<endl;
cin>>item;

cout<<"Array Before changing "<<endl;
for(int i=0;i<10;i++)
cout<<list[i]<<" ";
cout<<endl;

for(int i=0;i<10;i++)
if(list[i]==item)
list[i]=-100;

cout<<"Array After changing "<<endl;
for(int i=0;i<10;i++)
cout<<list[i]<<" ";
cout<<endl;

    system("pause");
    return 0;
}

ملاحظه : اذا دخل اليوزر رقم اصلا مو موجود في list مو حلوه نكتب after change وهو اصلاً مافي تغيير
فـ هني نقدر نسوي boolian و شرط بس انا ماحبيت اعقدها فـ تقبلوا الشكل
:RpS_lol:

السؤال الثاني
افرض عندنا array فيها 10 ارقام
المطلوب تطلب من اليوزر يدخل رقم عشان نشوف كم مره موجود في list يسمونه occurence

انا سويت لك مثال بسيط حطيت ارقام ثابته ، لكن انت تقدر تسوي برنامج مرتب يعني يطلب من اليوزر يدخل جميع الارقام في الArray
بعدين تطلب منه يدخل رقم عشان نشوفه كم مره متكرر

PHP:
#include<iostream>
using namespace std;
int main(){
    
    int list[10]={10,25,10,4,8,7,6,7,9,10};
    int item , count=0 ;

cout<<"Enter item : "<<endl;
cin>>item;

for(int i=0;i<10;i++)
if(list[i]==item)
count++;

if(count==0)
cout<<"Not Found"<<endl;
else
cout<<"Counter = "<<count<<endl;

    system("pause");
    return 0;
}


نسألكم الدعاء
 
جزاك الله الف خير :RpS_love::eek:
 
^ مشكور اخوي
هذا حل ثاني اول شي طلع قيمة غلط بعدين صار ايرور
الخلل في انه فور لوب داخل فور لوب يعني اذا قارن لازم كذا مرة للحرف الواحد بيتحقق الشرط حتى لو كان فاول بينطبع
فكرت بشرط أو طريقة لتفادي هالسالفة ما وصلت لنتيجة
و شكله هذا الحل معقد أزيد من الأول << شكلي أحب التعقيد :RpS_huh::nosweat:
​
كود:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string word1,word2;
int num=0;
string v="aAeEiIoOuU";
cout<<"Enter the word ";
getline(cin,word1);
for(int i=0;i<word1.length();i++)
{
for(int j=0;j<v.length();j++)
{
if(word1[i]==v[j])
{
    word2+=word1.substr(i,1);
    
}
    
cout<<"The new word is"<<word2;
return 0;
}

أظن يصير جذي .. :whistling:

كود:
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string word1,word2;
    int num;
    string v="aAeEiIoOuU";
    cout<<"Enter the word :\n";
    getline(cin,word1);
    for(int i=0;i<word1.length();i++)
    {
        for(int j=0;j<v.length();j++)
        {
            if(word1[i]!=v[j])
            num=1;
            else {num=0;break;}
        }
        cout<<word1[i]<<" "<<num<<endl;
        if(num)
        {word2+=word1[i];}
        cout<<word2<<endl;
    }
    cout<<"The new word is :\n"<<word2<<endl;
    system("pause");
    return 0;
}
 
عودة
أعلى أسفل