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

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

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

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

Insert Between Odds

كود:
#include <iostream>
using namespace std;

const int Max_Size=10;

//The first function
void Print(int arr[],int length)
{
    cout<<"Your Items : "<<endl;
    for(int i=0;i<length;i++)
    {
        cout<<arr[i]<<endl;
    }
    cin.get();
}

//the second function
void ShiftToRight(int Arr[],int pos,int length)
{
    for(int i=length-1;i>=pos;i--)
    {
        Arr[i+1]=Arr[i];
    }
    cin.get();
}

void insertBetweenOdds(int List[],int Length,int Max_Size)
{
    int sum=0;
    for(int i=0;i<Length;i++)
    {
        if(List[i]%2==1)
            if(List[i+1]%2==1)
            {
                if(Length+1 >= Max_Size)
                {
                    cout<<"The array is full"<<endl;
                    cin.get();
                    return;
                }
                else
                {
                    sum=List[i]+List[i+1];
                    ShiftToRight(List,i+1,Length);
                    List[i+1]=sum;
                    Length=Length+1;
                }
            }
    }
    Print(List,Length);
    cin.get();
}
void main()
{
    int myArray[Max_Size];
    int length;
    cout<<"Please enter the number of elements"<<endl;
    cin>>length;

    //take the values from the user
    cout<<"\nNow enter "<<length<<" values"<<endl;
    for(int i=0;i<length;i++)
    {
        cin>>myArray[i];
    }

    //Calling the function
    insertBetweenOdds(myArray,length,Max_Size);
    cin.get();
}
 
  • Like
التفاعلات: Lutos
سلام ..

ممكن أحد يصحح لي الأخطاء في هالأسايمنت ..

كود:
#include < iostream >
#include < string >
using namespace std;
{
    struct studenttype
    {
        string studentName ;
        int testScore ;
        char grade ;
    };

}
void readdata (StudentType x[],int length )
{
        cin>>x[i].studentName;
        cin>>x[i].testScore;
        cin>>x[i].grade;
}
void Assigngrade (int testScore )
{
    for(int i=0;i<length;i++)
        if ( score>=90)
        x.grade='A'
        else if ( score>=80&&score<=90)
        x.grade='B'
        else if ( score>=70&&score<=80)
        x.grade='C'
        else if ( score>=70&&score<=60)
        x.grade='D'
        else if ( score<60)
        x.grade='F'

}
void printdata ( studenttype x )
{
cout <<x.studentName<< endl;
cout <<x.testScore<< endl;
cout <<x.grade<< endl;
}
int main()
{
    studenttype student[3]
    for(int i=0;i<3;i++);
    read ( student[i]);
    Assign( student[i].testScore )
for(int i=0;i<3;i++);
    cout <<student[i]<< endl;
return0;
}
 
سلام ..

ممكن أحد يصحح لي الأخطاء في هالأسايمنت ..

كود:
#include < iostream >
#include < string >
using namespace std;
{
    struct studenttype
    {
        string studentName ;
        int testScore ;
        char grade ;
    };

}
void readdata (StudentType x[],int length )
{
        cin>>x[i].studentName;
        cin>>x[i].testScore;
        cin>>x[i].grade;
}
void Assigngrade (int testScore )
{
    for(int i=0;i<length;i++)
        if ( score>=90)
        x.grade='A'
        else if ( score>=80&&score<=90)
        x.grade='B'
        else if ( score>=70&&score<=80)
        x.grade='C'
        else if ( score>=70&&score<=60)
        x.grade='D'
        else if ( score<60)
        x.grade='F'

}
void printdata ( studenttype x )
{
cout <<x.studentName<< endl;
cout <<x.testScore<< endl;
cout <<x.grade<< endl;
}
int main()
{
    studenttype student[3]
    for(int i=0;i<3;i++);
    read ( student[i]);
    Assign( student[i].testScore )
for(int i=0;i<3;i++);
    cout <<student[i]<< endl;
return0;
}

عندش اخطاء صغيرة بس واااجد:RpS_wink:

الكود بعد التصحيح :

كود:
#include <iostream>
#include <string>
using namespace std;

    struct studenttype
    {
        string studentName ;
        int testScore ;
        char grade ;
    };


void readdata(studenttype& x)
{
        cin>>x.studentName;
        cin>>x.testScore;
}
void Assigngrade(studenttype& x,int score)
{
        if ( score>=90)
        x.grade='A';
        else if ( score>=80&&score<90)
        x.grade='B';
        else if ( score>=70&&score<80)
        x.grade='C';
        else if ( score>=60&&score<70)
        x.grade='D';
        else if ( score<60)
        x.grade='F';

}
void printdata ( studenttype x )
{
cout <<x.studentName<< endl;
cout <<x.testScore<< endl;
cout <<x.grade<< endl;
}
int main()
{
    studenttype student[3];
    for(int i=0;i<3;i++){
    readdata ( student[i]);
    Assigngrade(student[i], student[i].testScore );
    }
for(int i=0;i<3;i++)
    printdata(student[i]);
return 0;
}

حاولي تقارنين بينهم حق تعرفين الأخطاء :rolleyes2:
 
سلام ..

ممكن أحد يصحح لي الأخطاء في هالأسايمنت ..

كود:
#include < iostream >
#include < string >
using namespace std;
{
    struct studenttype
    {
        string studentName ;
        int testScore ;
        char grade ;
    };

}
void readdata (StudentType x[],int length )
{
        cin>>x[i].studentName;
        cin>>x[i].testScore;
        cin>>x[i].grade;
}
void Assigngrade (int testScore )
{
    for(int i=0;i<length;i++)
        if ( score>=90)
        x.grade='A'
        else if ( score>=80&&score<=90)
        x.grade='B'
        else if ( score>=70&&score<=80)
        x.grade='C'
        else if ( score>=70&&score<=60)
        x.grade='D'
        else if ( score<60)
        x.grade='F'

}
void printdata ( studenttype x )
{
cout <<x.studentName<< endl;
cout <<x.testScore<< endl;
cout <<x.grade<< endl;
}
int main()
{
    studenttype student[3]
    for(int i=0;i<3;i++);
    read ( student[i]);
    Assign( student[i].testScore )
for(int i=0;i<3;i++);
    cout <<student[i]<< endl;
return0;
}

في واجد اخطاء انا سويتلج كومينتات على السطور اللي فيها اخطاء بس الستركت عادي ينكتب قبل ال main

كود:
#include < iostream >
#include < string >
using namespace std;
[COLOR=#008000]//[/COLOR]{
    struct studenttype 
    {
        string studentName ;
        int testScore ;
        char grade ;
    };
    //}[COLOR=#008000]//this is wrong[/COLOR]
void readdata (studenttype x[],int length )//the struct name is not capital
{
   [COLOR=#008000] //there is nothing called i [/COLOR]
        cin>>x[i].studentName;
        cin>>x[i].testScore;
        cin>>x[i].grade;
}
void Assigngrade (int testScore )
{[COLOR=#008000]
    //ther is nothing called length[/COLOR]
    for(int i=0;i<length;i++)
        if ( score>=90)
        x.grade='A'//missing ; and there is nothing called x
        else if ( score>=80&&score<=90)
        x.grade='B'[COLOR=#008000]//missing[/COLOR] [COLOR=#008000];[/COLOR]
        else if ( score>=70&&score<=80)
        x.grade='C'[COLOR=#008000]//missing[/COLOR] [COLOR=#008000];[/COLOR]
        else if ( score>=70&&score<=60)
        x.grade='D'[COLOR=#008000]//missing[/COLOR] [COLOR=#008000];[/COLOR]
        else if ( score<60)
        x.grade='F'[COLOR=#008000]//missing[/COLOR] [COLOR=#008000];[/COLOR]

}
void printdata ( studenttype x )
{
cout <<x.studentName<< endl;
cout <<x.testScore<< endl;
cout <<x.grade<< endl;
}
int main()
{
    studenttype student[3]
    for(int i=0;i<3;i++);[COLOR=#008000]//no ; after this line[/COLOR]
    read ( student[i]);
    Assign( student[i].testScore )[COLOR=#008000]//missing ; and the function name is Assigngrade not Assign[/COLOR]
for(int i=0;i<3;i++);[COLOR=#008000]//no ; after this line [/COLOR]
    cout <<student[i]<< endl;
return0;[COLOR=#008000]//you must leave space between return and 0[/COLOR]
}
 
اذا مثلا طلبوا منا في السؤال , نكتب فنكشن و نسوي سيرج باستخدام الـBinary أو الـsequential , هل لازم الـarray تكون مرتبة ؟؟
 
اذا مثلا طلبوا منا في السؤال , نكتب فنكشن و نسوي سيرج باستخدام الـBinary أو الـsequential , هل لازم الـarray تكون مرتبة ؟؟
لازم في ال binary بس يكون مرتب بس في ال sequential عادي لان في كل الاحوال بيسوي لوب على كل ال items
 
التعديل الأخير:
  • Like
التفاعلات: Lutos
ليش في الـSelection sort+bubble sort..
نستخدم 2 nested Loops" loops" ..
شنو فايدة الفور لوب الأولى و الفور لوب الثانية , هل مثلا نقدر نستخدم فور لوب وحدة..
و ليش الفور لوب الأول تبدا من الصفر , و الفور لوب الثانية تبدأ بواحد في الـ
Bubble sort ..
HTML:
for(int i=1;i<length;i++)
{
for(intj=0;j<length-1;j++)


و في الـSeclection Sort , ليش الفور لوب الأولى تبدأمن الصفر و الفور لوب الثاني تبدأ من i+1
HTML:
for(int i=0;i<length;i++)
{
smallestIndex=i;
for(intj=i+1;j<length;j++)

ممكن توضيح للأشياء اللي في الكود ..
 
ليش في الـSelection sort+bubble sort..
نستخدم 2 nested Loops" loops" ..
شنو فايدة الفور لوب الأولى و الفور لوب الثانية , هل مثلا نقدر نستخدم فور لوب وحدة..
و ليش الفور لوب الأول تبدا من الصفر , و الفور لوب الثانية تبدأ بواحد في الـ


Bubble sort ..
HTML:
for(int i=1;i<length;i++)
{
for(intj=0;j<length-1;j++)


و في الـSeclection Sort , ليش الفور لوب الأولى تبدأمن الصفر و الفور لوب الثاني تبدأ من i+1
HTML:
for(int i=0;i<length;i++)
{
smallestIndex=i;
for(intj=i+1;j<length;j++)

ممكن توضيح للأشياء اللي في الكود ..

نسوي 2 loops عشان نقارن بين كل رقمين متجاورين فتكون فور لوب على اول رقم والثانيه على الرقم الثاني
يعني اذا الارقام 5,7,9,21,30,40
اول لوب تبدأ عند ال I=7 والثانيه عند ال J=5 نقارن ال 7 مع ال 5 لان اذا ال 2 بدأو مع بعض بتكون المقارنه بنفس الرقم ولما اسوي ++ بيروحو اثنينهم معا بعض على نفس الرقم مره ثانيه يعني اذا بدأت من 0 في الاثنين بتكون i=5 and j=5 واقارن فما بيصير شيئ لان الرقمين متساويبن وبعدين لما اسوي ++ تكون i=7 and j=7 واقارن بعد ما بيصير شيئ

لكن على الوضع هذا يصير J=7 و I=9 ونقارن
وتنتهي عند J=30 و I=40 ونقارن عشان جذي في ال LOOP الثانية J<LENGTH-1
يعني باختصار عشان يكون عندنا 2pointers على الارقام اللي بنقارنها ببعض
اتمنى يكون واضح :RpS_unsure: بس اذا مش واضح قوليلي انشاء الله بشرح بطريقه اوضح:smile:
 
  • Like
التفاعلات: Lutos
Problem 7:
a. Write a function named maxPosition that takes an array of integers intList, and the index of the last element last. The function should return the position (location) of the maximum element in the array. The function prototype is:
int maxPosition(int intList[ ], int last);
For example, if last = 9, and intList contains the following elements:
25 99 35 40 45 50 55 888 65 70
Then, the function should return 7, but if the function is called with the value last=6, then the function should return 1.

b. Use the function in part (a) to write a selection sort function to sort an array of
integers in ascending order (Low to High).
​

HTML:
# include<iostream>
using namespace std;
int maxposition(int list[],int last);
{
    int MaxIndex;
    for(int i=0;i<last;i++)
    {
        if(list[i]==MaxIndex)
            return i;
        return -1;
    
    else if(list[i]==last-3)return 1;
    }
    
    void Selection sort(int list[],int length);
    {
        int smallestIndex,temp;
        for(int i=0;i<length;i++)
        {
            smallestIndex=i;
            for(int j=i+1;j<length;j++)
                if(list[i]<list[smallestIndex])
            smallestIndex=j;
            temp=list[smallestIndex]};
            list[smallestIndex]=list[i];
            list[i]=temp;
    }

}
void main()
{
    int list[9]={25,99,35,40,45,50,55,888,65,70};
     maxposition(list,9);
}

ممكن تشوفون حلي ..

​
 
DateType​

ممكن احد يجوف الايرورات

ضروري

HTML:
#include<iostream>
using namespace std;
struct DateType
{
int Day ;
int Month ;
int year;
};
struct SudentType
{
int studentid;
DateType studentbirthdate;
double marks[36];
int nbc;
};
double calavr(SudentType x)
{
double total = 0;
for(int i=0;i<x.nbc;i++)
total += x.marks[i];
return total/x.nbc;
}
void printstudent(SudentType x)
{
cout<< "studentid:"<<x.studentid<<" student birthdate:"<<x.studentbirthdate.Day<<" / "<< x.studentbirthdate.Month <<"/"<< x.studentbirthdate.year;
cout<< "marks:";
for( int i = 0; i < x.nbc;i++)
cout<<x.marks[i]<<endl;
}
int beststudent(SudentType list[],int s)
{
int max = 0;
for(int i =1; i<s;i++)
if(calavr.list[i]>calavr.list[max])
max =i;
return max;
int main()
{
SudentType s[40];
for (int i =0;i>3;i++)
{cout<<"enter id:";
cin>> s[i].studentid;
cout<< "enter birthday( dd/mm/yy):";
cin>> s[i].studentbirthdate.day>>s[i].studentbirthdate.month>> s[i].studentbirthdate.year;
cout<<" how many courses:";
cin>> s[i].nbc;
cout<<"enter marks:";
for(int j=0;i< s[i].nbc;j++)
cin>> s[i].marks[j];
}
cout<<"id of best student"<< s [ beststudent(s,3)].studentid;
for (int i =0; i>3;i++ )
printstudent( s[i] );
return 0; 
 
}
 
Problem 7:
a. Write a function named maxPosition that takes an array of integers intList, and the index of the last element last. The function should return the position (location) of the maximum element in the array. The function prototype is:
int maxPosition(int intList[ ], int last);
For example, if last = 9, and intList contains the following elements:
25 99 35 40 45 50 55 888 65 70
Then, the function should return 7, but if the function is called with the value last=6, then the function should return 1.

b. Use the function in part (a) to write a selection sort function to sort an array of
integers in ascending order (Low to High).
​

HTML:
# include<iostream>
using namespace std;
int maxposition(int list[],int last);
{
    int MaxIndex;
    for(int i=0;i<last;i++)
    {
        if(list[i]==MaxIndex)
            return i;
        return -1;
    
    else if(list[i]==last-3)return 1;
    }
    
    void Selection sort(int list[],int length);
    {
        int smallestIndex,temp;
        for(int i=0;i<length;i++)
        {
            smallestIndex=i;
            for(int j=i+1;j<length;j++)
                if(list[i]<list[smallestIndex])
            smallestIndex=j;
            temp=list[smallestIndex]};
            list[smallestIndex]=list[i];
            list[i]=temp;
    }

}
void main()
{
    int list[9]={25,99,35,40,45,50,55,888,65,70};
     maxposition(list,9);
}

ممكن تشوفون حلي ..

​


خطأ

شكلش ما فهمتين السؤال عدل
المطلوب في القسم الاول فنكشن ترجع (((موقع)))) أكبر رقم في اللستة بشرط ان يكون قبل last فبتصير :

كود:
int maxPosition(int intList[], int last){
    int max=0;
    for(int i=1;i<=last;i++)
        if(intList[i]>intList[max])
            max=i;
    return max;}


المطلوب في القسم الثاني هو ان نستخدم الفنكشن الي سويناها في ترتيب اللستة بطريقة selection sort , والفنكشن الي عندنا تدور اكبر رقم وليس الاصغر , يعني لازم نعكس السالفة:nosweat:

كود:
void selsort(int intList[],int last){
    int i,maxindex;
    for( i=last;i>0;i--){
    maxindex=maxPosition(intList,i);
    int temp=intList[maxindex];
    intList[maxindex]=intList[i];
    intList[i]=temp;
    }}


المين فنكشن للتأكد من الحل


كود:
    int main(){
        int x[10]={25,99,35,40,45,50,55,888,65,70};
        int last=9;
        selsort(x,last);
        for(int i=0;i<last+1;i++)
            cout<<x[i]<<ends;
        cout<<endl;
    }
 
  • Like
التفاعلات: Lutos
DateType​

ممكن احد يجوف الايرورات

ضروري

HTML:
#include<iostream>
using namespace std;
struct DateType
{
int Day ;
int Month ;
int year;
};
struct SudentType
{
int studentid;
DateType studentbirthdate;
double marks[36];
int nbc;
};
double calavr(SudentType x)
{
double total = 0;
for(int i=0;i<x.nbc;i++)
total += x.marks[i];
return total/x.nbc;
}
void printstudent(SudentType x)
{
cout<< "studentid:"<<x.studentid<<" student birthdate:"<<x.studentbirthdate.Day<<" / "<< x.studentbirthdate.Month <<"/"<< x.studentbirthdate.year;
cout<< "marks:";
for( int i = 0; i < x.nbc;i++)
cout<<x.marks[i]<<endl;
}
int beststudent(SudentType list[],int s)
{
int max = 0;
for(int i =1; i<s;i++)
if(calavr.list[i]>calavr.list[max])
max =i;
return max;
int main()
{
SudentType s[40];
for (int i =0;i>3;i++)
{cout<<"enter id:";
cin>> s[i].studentid;
cout<< "enter birthday( dd/mm/yy):";
cin>> s[i].studentbirthdate.day>>s[i].studentbirthdate.month>> s[i].studentbirthdate.year;
cout<<" how many courses:";
cin>> s[i].nbc;
cout<<"enter marks:";
for(int j=0;i< s[i].nbc;j++)
cin>> s[i].marks[j];
}
cout<<"id of best student"<< s [ beststudent(s,3)].studentid;
for (int i =0; i>3;i++ )
printstudent( s[i] );
return 0; 
 
}

كود:
if(calavr.list[i]>calavr.list[max])
calavr فنكشن مو ستركت فاذا بتسوي ليه كول لازم تستعمل اقواس وليس .
كود:
if(calavr(list[i])>calavr(list[max]))

كود:
for (int i =0;i>3;i++)
كأن المفروض الآي اتصير اصغر من 3 :smile:

كود:
cin>> s[i].studentbirthdate.day>>s[i].studentbirthdate.month>> s[i].studentbirthdate.year;

ال day و ال month لازم اول حرف كبيتال لتر لانك عرفته كبتل لتر فوق في الستركت الاولي
كود:
cin>> s[i].studentbirthdate.Day>>s[i].studentbirthdate.Month>> s[i].studentbirthdate.year;
 
  • Like
التفاعلات: m.g.s
البرنامج عبارة ستركت للبيانات
البيانات اتكون موجودة في فايل
فانسوي فنكشن تقرأ البيانات من الفايل الى أري
بعدين لما
toPay>999.0&&toPay<7500.0
يطبع عالسكرين بيانات الشخص الي عنده هالشرط

هذا الكود الي سويناه .. فيه ايرور
ممكن اشوفونه


كود:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct name
{
string firstName;
string midName;
string lastName;
};
struct data
{
    int day;
    int month;
    int year;
};
struct patientType
{
name patname;
date entryDate;
long patCPR;
double patAge;
char patGender;
double toPay;
};
void getData (struct patienttype[],int pasSize);
{
ifstream infile;
infile.open("patien.txt");
for(int i=0;i<pasSize;i++)
infile>>patienttype[i].firstName;
infile>>patienttype[i].midtName;
infile>>patienttype[i].lastName;
infile>>patienttype[i].patCPR;
infile>>patienttype[i].patAge;
infile>>patienttype[i].patGender;
infile>>patienttype[i].day;
infile>>patienttype[i].month;
infile>>patienttype[i].year;
infile>>patienttype[i].toPay;
infile.close()
}
int main()
{
toPay  patienttype[];
int i;
for(i=0;i<pasSize;i++)
{


if(patienttype[] toPay>999.0&&toPay<7500.0)
{
cout>>patienttype[i].firstName;
cout<<patienttype[i].midtName;
cout<<patienttype[i].lastName;
cout<<patienttype[i].patCPR;
cout<<patienttype[i].patAge;
cout<<patienttype[i].patGender;
cout<<patienttype[i].day;
cout<<patienttype[i].month;
cout<<patienttype[i].year;
cout<<patienttype[i].toPay;
}


}
 
كود:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct name
{
string firstName;
string midName;
string lastName;
};
struct data
{
    int day;
    int month;
    int year;
};
struct patientType
{
name patname;
date entryDate;
long patCPR;
double patAge;
char patGender;
double toPay;
};
void getData (struct patienttype[],int pasSize);
{
ifstream infile;
infile.open("patien.txt");
for(int i=0;i<pasSize;i++)
infile>>patienttype[i].firstName;
infile>>patienttype[i].midtName;
infile>>patienttype[i].lastName;
infile>>patienttype[i].patCPR;
infile>>patienttype[i].patAge;
infile>>patienttype[i].patGender;
infile>>patienttype[i].day;
infile>>patienttype[i].month;
infile>>patienttype[i].year;
infile>>patienttype[i].toPay;
infile.close()
}
int main()
{
toPay  patienttype[];
int i;
for(i=0;i<pasSize;i++)
{




if(patienttype[] toPay>999.0&&toPay<7500.0)
{
cout>>patienttype[i].firstName;
cout<<patienttype[i].midtName;
cout<<patienttype[i].lastName;
cout<<patienttype[i].patCPR;
cout<<patienttype[i].patAge;
cout<<patienttype[i].patGender;
cout<<patienttype[i].day;
cout<<patienttype[i].month;
cout<<patienttype[i].year;
cout<<patienttype[i].toPay;
}




}


هذا البرنامج بدون اخطاء وان شاء الله يكون نفس البرنامج اللي تبينه
كود:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;




struct name
{
string firstName;
string midName;
string lastName;
};




struct data
{
    int day;
    int month;
    int year;
};




struct patientType
{
name patname;
data entryDate;
long patCPR;
double patAge;
char patGender;
double toPay;
};






void getData (patientType patients[],int pasSize)
{
ifstream infile;
infile.open("patien.txt");


for(int i=0;i<pasSize;i++)
{
infile>>patients[i].patname.firstName;
infile>>patients[i].patname.midName;
infile>>patients[i].patname.lastName;
infile>>patients[i].patCPR;
infile>>patients[i].patAge;
infile>>patients[i].patGender;
infile>>patients[i].entryDate.day;
infile>>patients[i].entryDate.month;
infile>>patients[i].entryDate.year;
infile>>patients[i].toPay;
infile.close();
}}






int main()
{
patientType patients[100];


int i,pasSize=5;




for(i=0;i<pasSize;i++)
{
    if( patients[1].toPay > 999.0 &&  patients[1].toPay < 7500.0 )
    {
    cout<<patients[i].patname.firstName;
    cout<<patients[i].patname.midName;
    cout<<patients[i].patname.lastName;
    cout<<patients[i].patCPR;
    cout<<patients[i].patAge;
    cout<<patients[i].patGender;
    cout<<patients[i].entryDate.day;
    cout<<patients[i].entryDate.month;
    cout<<patients[i].entryDate.year;
    cout<<patients[i].toPay;


    }
}
}


عندش مشكله ان الستركت اذا سويتينه لازم تعطينه فيريابل وتستخدمين هذا الفيريابل ،، لان الستركت حاله حال الانتجر ما يصير تقولين
int[5]
لازم
int x[5]


وشغله ثانيه اذا عرفنه ستركت داخل ستركت وبستخدم ممبر من الستركت الداخلي لازم نكتب اسم الستركتين
patients.patname.firstName

وبعد انا خليت رقم من عندي في الاري
والpasSize عطيته رقم 5 بعد من عندي ،، يعني عدليه على حسب اللي تبينه
او تسوينه cin



:smile::smile:
​
 
عاجل..طوارئ..لا تبخلون ساعدوني"اي تي سي اس 104"

سلام

عندي اسايمنت في سي اس 104

هو مرتبط بالاسايمنت الخامس الي قبله
عندي حل الاسايمنت الي قبله بس لازم اضافات
وهالاضافات هي الاسايمنت السادس
بحط السؤال وبحط ليكم جواب الاسايمنت الاول
ان شاء الله ما تبخلون
لازم اسلمه اليوم قبل الساعة 12
​

  1. [*=center]Use the same class of the last lab and add the following member's functions:

  1. [*=center]constructor with default parameters

  • [*=center]Empty strings(" ") for ItemName and ItemType)
    [*=center]0 for the ItemPrice.
The constructor must output the following message:"Object has been created".​

  1. [*=center]Destructor function that output the following message:"Object has been deleted".

2. In the main function answer the following five questions to test the class MenuType.​

  1. [*=center]Write one statement to declare an array Name MenuList with maximum size 50 of Type the class MenuType.
    [*=center]Write the code to enter (from the user) data of 4 objects into array MenuList .
    [*=center]Write the code to output only items offered in "Lunch" time.
    [*=center]Output all data of the array MenuList.

cpp.

# include <iostream>
# include "MenuType.h"
#include<string>
using namespace std;
int main()
{
MenuType plate1;
plate1.setItem("Plan Egg",5.2,"Breakfast");
plate1.IncreasePrice(1.2);
plate1.showMenu();
system (pause");
return 0;
}

cpp.
# include <iostream>
#include"MenuType.h"
#include<string>
using namespace std;
MenuType::MenuType()
{
ItemName=" ";
ItemPreice=0.0;
ItemType=" ";
void MenuType::setItem(string x,float y,string z)
{
ItemName=x;
ItemPrice=y;
ItemType=z;
}
void MenuType::IncreasePrice(float y)
{
ItemPrice += y;
}
bool MenuType::SameValue(MenuType other)
{
if (ItemPrice==other.ItemPrice)
return true;
else
return false;
}
void MenuType::showMenu ()
{
coue<<ItemName<<" "<<ItemPrice<<" "<<ItemType<<endl;
}

" .h "
#include <string>
using namespace std;
class MenuType
{
private:
string ItemName;
float ItemPrice;
string ItemType;
public:
void setItem (string x,float y,string z);
void gatItem (string &x, float &y,string &z);
void IncreasePrice (float y);
bool SameValue (MenuType other);
void showMenu();
MenuType();
};

​
 
شلون نفرق بين Arrays in structs و structs in Arrays ..
أو أهما نفس الشيء ؟؟
اذا بييبون لنا اسئلة , هل بيوضحون اذا نستخدم Arrays in structs أو structs in Arrays ؟؟
 
اصير احد ايجوف الايرورات (ضروري ) :RpS_crying:
#include<iostream>
using namespace std;
class menutype
{
private:
string name;
float price;
public:
menutype();
void setdata(string,float);
string getname();
float getprice();
void display();
~menutype();
};
menutype::menutype()
{
name="";price=0.0;
}
void menutype::setdata(string in,float ip)
{
name=in;price=ip;name;
}
string menutype::getname()
{
string in;
return in=name;
}
float menutype::getprice()
{
float ip;
return ip=price;
}
void menutype::display()
{
cout<<name<<endl;
cout<<price<<endl;
}
menutype::~menutype()
{
cout<<"item deleted"<<endl;
}
int main()
{
menutype item1,item2;
item1.setdata("rice",1.5);
item2.setdata("fish",3.5);
if(item1.getprice()<item2.getprice())
{
cout<<item1.getnam();
}
else
if(item1.getprice()>item2.getprice())
{
cout<<item2.getname();
}
system("pause");
return 0;
}
​
 
اصير احد ايجوف الايرورات (ضروري ) :RpS_crying:
#include<iostream>
using namespace std;
class menutype
{
private:
string name;
float price;
public:
menutype();
void setdata(string,float);
string getname();
float getprice();
void display();
~menutype();
};
menutype::menutype()
{
name="";price=0.0;
}
void menutype::setdata(string in,float ip)
{
name=in;price=ip;name;
}
string menutype::getname()
{
string in;
return in=name;
}
float menutype::getprice()
{
float ip;
return ip=price;
}
void menutype::display()
{
cout<<name<<endl;
cout<<price<<endl;
}
menutype::~menutype()
{
cout<<"item deleted"<<endl;
}
int main()
{
menutype item1,item2;
item1.setdata("rice",1.5);
item2.setdata("fish",3.5);
if(item1.getprice()<item2.getprice())
{
cout<<item1.getnam();
}
else
if(item1.getprice()>item2.getprice())
{
cout<<item2.getname();
}
system("pause");
return 0;
}
​

- ضيفي في البداية #include < string >0
- في المين : أول شرط if مسوية كول للفنكشن getname ناسية تحطين حرف الـ "e"
 
Bubble Sort
كود:
void bubbleSort(int list[], int length)
{
    int temp;
    int iteration;
    int index;
 
    for (int i = 1; i < length; i++)
    {
        for (j= 0; j < length - i; j++)
            if (list[j] > list[j + 1]) 
            {
                temp = list[j];
                list[j] = list[j + 1];
                list[j + 1] = temp;
            }
    }
}

اذا مثلا :
عندي arr[5]:20 15 12 22 10
و أبغي أسوي لهم sort ..
المرة الأولى صارت لي
22 10 20 12 15 و بعد أبغي أسوي لهم Sort شلون , الـsort يوقف اذا كل العناصر صارت مرتبة ؟
مو المفترض الـ sort يصير مرة واحدة فقط !
اللي فهمته ان :

​
i=1///////j=0
1
2
3
4

وبهالطريقة قدرت أسوي الـsort , لكن ما عرفت أكمل ..
المفروض في النهاية يصير 22 20 15 12 10
ممكن توضيح ؟
 
عودة
أعلى أسفل