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

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

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

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

ما في شيء جديد ؟ :nosweat:
​
 
بجيب ليكم سؤالين مال الاسايمنت اليوم
 
write a function called "insertcomma" that takes a string" sentence" as input parameter and returns the new sentence after inserting comma before each space in the sentence
 
write a program that reads two strings , sentence and word , from the user and display the new sentence after removing all occurrences of word in the sentence >> اني حليته بال erase اذا ممكن تحلونة بطريقه ثانيه :smile2:
PHP:
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,word;
	int len,lens,position;
	
	cout<<" enter a string :";
	getline(cin,s);
	cout<<endl;
	cout<<"enter a word :";
	cin>>word;
	cout<<endl;
	len=word.length();
	lens=s.length();
	
		for (int i=0;i<lens;i++)
		{
		
		position=s.find(word);
		if (position>=0 && position<lens)
			s.erase(position,len);
		}
 
	cout<<"the new string is :"<<s<<endl;
	return 0;
}
 
 
 
write a function called "insertcomma" that takes a string" sentence" as input parameter and returns the new sentence after inserting comma before each space in the sentence
اعتقد جدي الحل :
PHP:
#include<iostream>
#include<string>
using namespace std;
string insertcomma(string str1){
    int size=str1.size();
    for(int i=0;i<size;i++){
        if(str1[i]==' '){str1[i]=', ';}
    }
    return str1;}
int main(){
    string str1;
    getline(cin,str1);
    cout<<insertcomma(str1);
    return 0;}
// Ali Hassan
 
التعديل الأخير:

اعتقد جدي الحل :
PHP:
#include<iostream>
#include<string>
using namespace std;
string insertcomma(string str1){
    int size=str1.size();
    for(int i=0;i<size;i++){
        if(str1[i]==' '){str1[i]=',';}
    }
    return str1;}
int main(){
    string str1;
    getline(cin,str1);
    cout<<insertcomma(str1);
    return 0;}
// Ali Hassan

صح الجواب بس لازم المسافة تظل موجوده انت بس تسوي ريبليس
 
write a program that reads two strings , sentence and word , from the user and display the new sentence after removing all occurrences of word in the sentence >> اني حليته بال erase اذا ممكن تحلونة بطريقه ثانيه :smile2:
PHP:
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s,word;
    int len,lens,position;
    
    cout<<" enter a string :";
    getline(cin,s);
    cout<<endl;
    cout<<"enter a word :";
    cin>>word;
    cout<<endl;
    len=word.length();
    lens=s.length();
    
        for (int i=0;i<lens;i++)
        {
        
        position=s.find(word);
        if (position>=0 && position<lens)
            s.erase(position,len);
        }
 
    cout<<"the new string is :"<<s<<endl;
    return 0;
}
 
 

هذا بطريقة ثانية .. :whistling:

كود:
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s,word;
    int len,lens,position,x;
    
    cout<<"enter a string :\n";
    getline(cin,s);
    cout<<endl;
    cout<<"enter a word :\n";
    cin>>word;
    cout<<endl;
    len=word.length();
    lens=s.length();
    
        for (int i=0;i<lens;i++)
        {
        position=s.find(word);
        if (position!=-1)
        s=s.substr(0,position)+s.substr(position+len);
        }
    cout<<"the new string is :\n"<<s<<endl;
    system("pause");
    return 0;
}
نقدر نخلي الشرط ..
كود:
if (position!=string::npos)
 
write a function called "insertcomma" that takes a string" sentence" as input parameter and returns the new sentence after inserting comma before each space in the sentence

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

كود:
#include<iostream>
#include<string>
using namespace std;
string insertcomma(string str)
{
    int size=str.size();
    for(int i=0;i<size;i++){
    i=str.find(' ',i+1);
    if(str.find(' ',i)==-1) break;
    else str=str.substr(0,str.find(' ',i))+","+str.substr(str.find(' ',i));}
    return str;
}
int main()
{
    string sentence;
    getline(cin,sentence);
    cout<<insertcomma(sentence)<<endl;
    system("pause");
    return 0;
}
 
التعديل الأخير:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s,word;
int len,lens,position,x;

cout<<"enter a string :\n";
getline(cin,s);
cout<<endl;
cout<<"enter a word :\n";
cin>>word;
cout<<endl;
len=word.length();
lens=s.length();

for (int i=0;i<lens;i++)
{
position=s.find(word);
if (position!=-1)
s=s.substr(0,position)+s.substr(position+len);
}
cout<<"the new string is :\n"<<s<<endl;
system("pause");
return 0;
}
صحيييح :msn-wink:
#include<iostream>
#include<string>
using namespace std;
string insertcomma(string str)
{
int size=str.size();
for(int i=0;i<size;i++){
i=str.find(' ',i+1);
if(str.find(' ',i)==-1) break;
else str=str.substr(0,str.find(' ',i))+","+str.substr(str.find(' ',i));}
return str;
}
int main()
{
string sentence;
getline(cin,sentence);
cout<<insertcomma(sentence)<<endl;
system("pause");
return 0;
}
وينك ما تجي تغششنا في اللاب :whistling:
 
جبت لكم اليوم برنامج بسيط حق درس الbubble sorting / chapter 10
PHP:
#include<iostream>
using namespace std;
int main()
{
	int list[]={2,9,4,3,8,1,7};
	int temp;
 
	for (int i=0;i<7;i++)
	{
		for (int j=0;j<7-i-1;j++)
		{
		if (list[j]>list[j+1])
		{
			temp=list[j];
			list[j]=list[j+1];
			list[j+1]=temp;
		}
		}
	}
	for (int x=0;x<7;x++)
		cout<<list[x]<<endl;
	return 0;
}
 
 
جبت لكم اليوم برنامج بسيط حق درس الbubble sorting / chapter 10
PHP:
#include<iostream>
using namespace std;
int main()
{
    int list[]={2,9,4,3,8,1,7};
    int temp;
 
    for (int i=0;i<7;i++)
    {
        for (int j=0;j<7-i-1;j++)
        {
        if (list[j]>list[j+1])
        {
            temp=list[j];
            list[j]=list[j+1];
            list[j+1]=temp;
        }
        }
    }
    for (int x=0;x<7;x++)
        cout<<list[x]<<endl;
    return 0;
}
 

الإجابة صحيحة .. :nosweat:
و هذي إجابتي

كود:
#include<iostream>
using namespace std;
int main()
{
    int list[]={2,9,4,3,8,1,7};
    int temp;
    for (int i=0;i<7;i++)
    {
        for (int j=i+1;j<7;j++)
        {
        if (list[i][COLOR=#ff0000]>[/COLOR]list[j])
        {
            temp=list[i];
            list[i]=list[j];
            list[j]=temp;
        }
        }
    }
    for (int x=0;x<7;x++)
        cout<<list[x]<<" ";
        cout<<endl;
        system("pause");
    return 0;
}

وإذا كان المطلوب ترتيب تنازلي بس نغير ..

كود:
if (list[i][COLOR=#ff0000]<[/COLOR]list[j])
 
التعديل الأخير:
بنرد نرجعكم لدرس السترنق :whistling: write a fuction reverse that reverses a string passed as a parameter , assume the function prototype is " void reverse(string &s)
 
بنرد نرجعكم لدرس السترنق :whistling: write a fuction reverse that reverses a string passed as a parameter , assume the function prototype is " void reverse(string &s)
HTML:
#include<iostream>
#include<string>
using namespace std;
void reverse(string &s)
	{ 
		for (int i=s.length()-1;i>=0;i--)
			cout<<s[i];
		cout<<endl;
}
int main()
{
	string v;
	v="victory";
	reverse(v);
	return 0;
}
 
وهذا حلنا :rolleyes2:
 
write a function NoDupplication which takes a string as a parameter and removes all repetitions of characters from it , assume the function prototype is " string NoDupplication(string s)" ,,, then write a program for the function ,, مو مطلوب program بس من عندي حق الاستفاده :nosweat:
 
write a function NoDupplication which takes a string as a parameter and removes all repetitions of characters from it , assume the function prototype is " string NoDupplication(string s)" ,,, then write a program for the function ,, مو مطلوب program بس من عندي حق الاستفاده :nosweat:

كود:
#include<iostream>
#include<string>
using namespace std;
string NoDupplication(string s)
{
    for (int i=0;i<s.size();i++)
    if (s[i]==s[i+1])
    {s.erase(i,1);i--;}
    return s;
}
int main()
{
    string str;
    getline(cin,str);
    cout<<NoDupplication(str)<<endl;
    system("pause");
    return 0;
}
 
:whistling::whistling::whistling:

بالنسبة لذا البرنامج لو بغيت اطلع ليي ال length مع ال spaces مثلا ali jasem بغيته يطلع 9 مو يطبع كل كلمة بروحها

و ال min مثل الشيء يطلع اقصر اسم بالسبيسات:sad_1: :sad_1:

ان شاء الله فاهميني :bleh: :bleh:​

​

HTML:
#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;
}
 
:whistling::whistling::whistling:

بالنسبة لذا البرنامج لو بغيت اطلع ليي ال length مع ال spaces مثلا ali jasem بغيته يطلع 9 مو يطبع كل كلمة بروحها

و ال min مثل الشيء يطلع اقصر اسم بالسبيسات:sad_1: :sad_1:

ان شاء الله فاهميني :bleh: :bleh:

PHP:
#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())
    {
        getline(in,str);
        out<<str.length()<<endl;
        if (str.length()<min)min=str.length();
    }
    cout<<"Maimum name size : "<<min<<endl;
    system("pause");
    return 0;
}

* تعديل على كود Noise ... مجرد إضافة getline
أمّا بالنسبة إلى الـ Spaces فبيطول الحل إذا بغينا نحذف الـ Spaces

و بالتوفيق جميعًا :smile2:
​
 
write a program to read 10 names from file "names.dat" and print thier name length to file " namelength.dat".
In addition print the maximum and minimum length on screen

PHP:
 #include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str;
int x=10 , y=10;
ifstream in;in.open("names.dat");
ofstream out;out.open(" namelength.dat");
if (!in)
{
cout<<"Sorry No File";
return 1;
}
while(!in.eof())
{
getline(in,str);
out<<str.length()<<endl;
if (str.length()>x)
x=str.length();
else if (str.length()<y)
y=str.length();
}
cout<<"Maxmum name size : "<<x<<endl;
cout<<endl;
cout<<"Maimum name size : "<<y<<endl;
system("pause");
return 0;
}
وش الخطأ البرنامج موراضي يشتغل
:RpS_crying:
​
 
عودة
أعلى أسفل