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

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

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

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

في احد يقدر يحطلنا الحل مال بروبلم 7 توتريال 1
واكون شاكره لكم :99:
 
ممكن مساعدة في حل برنامج يا شطار IT104

ممكن اتساعدوني في حل هدا البرنامج واكون شاكرة لكم والله يقضي حوايجكم
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 is part (a) to write a selection sort function to sort an array of integers in ascending order (Low to High).
 
ممكن حل هدا البرنامج​
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 is part (a) to write a selection sort function to sort an array of integers in ascending order (Low to High).
 
تفضلي اختي هذا الحل
استفيدي منه ، بس لاتعتمدين عليه كامل
لان بارت تو من السؤال انا ما التزمت بالمكتوب
سويته بطريقه ثانيه

PHP:
#include <iostream>
using namespace std;
   
int maxPosition(int list[], int size)
{
    int locOfmax , max=list[0] ;
    int temp , smallestindex;
    
    for(int i=0 ; i<size ; i++)
    if(list[i]>max)
    {  max=list[i];
       locOfmax=i;
       }                      
       
for (int k=0 ; k<size-1 ; k++) //start code of sort
    {
        smallestindex=k;
        for(int minindex=k+1 ; minindex<size ; minindex++)
                if(list[minindex]<list[smallestindex])
         smallestindex=minindex;
         
        temp=list[smallestindex];
        list[smallestindex]=list[k];
        list[k]=temp;
    }                                   //end code of sort
   
         return locOfmax;     
               
}
       
    int main()
{
    
    int array[10]={1,2,5,7,8,9,10,45,15,20};
    int r = maxPosition(array,10);
    cout<<"The max. number is in index "<<r<<endl;
    
       cout<<"Array after sotring "<<endl;
    for(int j=0 ; j<10 ;j++)
    cout<<array[j]<<" ";
    
    system("pause");
     return 0;
}

نسألكم الدعاء
 
LAB ASSIGNMENTA) Define a struct called bookType that holds the following information about a book: a. Title (string),b. Price (float),c. Number of copies in stock(int). B) write a function called ReadOnebook that receives a struct bookType variable by reference and reads all the components of the variable.C) write a function called OutputOnebook that receives a struct bookType variable and outputs all the components of the variable.D) Write a function called outofstock that receives an array of struct bookType and outputs Tiles of books with 0 copies in stock . Write a main function that uses the struct bookType and tests the above functions.· Declare an array of type bookType maxsize=100 named S.· Read data of 3 books into S by calling ReadOnebook.· Output Data of each book OutputOnebook. · Output Tiles of only books with 0 copies in stock use OutputOnebook. Example of data:​
[TABLE="class: MsoTableGrid"]
[TR]
[TD="width: 89, bgcolor: transparent"]
Title​
[/TD]
[TD="width: 89, bgcolor: transparent"]
Price​
[/TD]
[TD="width: 273, bgcolor: transparent"]
Nb copies​
[/TD]
[/TR]
[TR]
[TD="width: 89, bgcolor: transparent"]
AAA​
[/TD]
[TD="width: 89, bgcolor: transparent"]
1​
[/TD]
[TD="width: 273, bgcolor: transparent"]
0​
[/TD]
[/TR]
[TR]
[TD="width: 89, bgcolor: transparent"]
BBB​
[/TD]
[TD="width: 89, bgcolor: transparent"]
0.5​
[/TD]
[TD="width: 273, bgcolor: transparent"]
55​
[/TD]
[/TR]
[TR]
[TD="width: 89, bgcolor: transparent"]
CCC​
[/TD]
[TD="width: 89, bgcolor: transparent"]
2.5​
[/TD]
[TD="width: 273, bgcolor: transparent"]
0​
[/TD]
[/TR]
[/TABLE]


heeeelllp 3aaaad :'''''(
 
LAB ASSIGNMENTA) Define a struct called bookType that holds the following information about a book: a. Title (string),b. Price (float),c. Number of copies in stock(int).B) write a function called ReadOnebook that receives a struct bookType variable by reference and reads all the components of the variable.C) write a function called OutputOnebook that receives a struct bookType variable and outputs all the components of the variable.D) Write a function called outofstock that receives an array of struct bookType and outputs Tiles of books with 0 copies in stock . Write a main function that uses the struct bookType and tests the above functions.· Declare an array of type bookType maxsize=100 named S.· Read data of 3 books into S by calling ReadOnebook.· Output Data of each book OutputOnebook. · Output Tiles of only books with 0 copies in stock use OutputOnebook. Example of data:​
[TABLE="class: MsoTableGrid"]
[TR]
[TD]
Title​
[/TD]
[TD="width: 89, bgcolor: transparent"]
Price​
[/TD]
[TD="width: 273, bgcolor: transparent"]
Nb copies​
[/TD]
[/TR]
[TR]
[TD="width: 89, bgcolor: transparent"]
AAA​
[/TD]
[TD="width: 89, bgcolor: transparent"]
1​
[/TD]
[TD="width: 273, bgcolor: transparent"]
0​
[/TD]
[/TR]
[TR]
[TD="width: 89, bgcolor: transparent"]
BBB​
[/TD]
[TD="width: 89, bgcolor: transparent"]
0.5​
[/TD]
[TD="width: 273, bgcolor: transparent"]
55​
[/TD]
[/TR]
[TR]
[TD="width: 89, bgcolor: transparent"]
CCC​
[/TD]
[TD="width: 89, bgcolor: transparent"]
2.5​
[/TD]
[TD="width: 273, bgcolor: transparent"]
0​
[/TD]
[/TR]
[/TABLE]


heeeelllp 3aaaad :'''''(

PHP:
#include<iostream>
#include<string>
 using namespace std;
 struct bookType
 {
 string title;
 float price;
 int c;
 };
 void ReadOnebook (bookType &book)
 {
 cout << "Enter Book Title: " ;
 cin >> book.title;
 cout << "Enter Book price: " ;
 cin >> book.price;
 cout << "Enter Number of copies : " ;
 cin >> book.c;
 cout << endl;
 }
 void OutputOnebook(bookType book)
 {
 cout << " Book Title: " << book.title;
 cout << " Book price: " << book.price;
 cout << " Number of copies: " << book.c;
 cout << endl;
 }
 void outofstock (bookType book[],int num)
 {
  for(int i=0;i<num;i++)
 if(book[i].c == 0)
 cout << "Zero copies " << book[i].title << endl; 
}

 int main()
 {
 int NOB;
 bookType S[100];
 cout << "Enter the number of books ";
 cin >> NOB;
 for(int i=0;i<NOB;i++)
 ReadOnebook (S[i]);
 for(int i=0;i<NOB;i++)
 OutputOnebook (S[i]);

 outofstock(S,NOB);
 return 0;
 }
 
سلام عليكم ..

طلب ضروري ضروري .. إلي في سكشن 2

دكتورة الاب أمس شرحت Assignment 2 وكتبت على سبورة تكملة جدول
Sample input/output ..وطبعاً شرح أساينمت .. لي كتب لي على سبورة

ما مداني أكتبه ..

ينزله وبكون شاكر له
​
 
سلام عليكم ..

طلب ضروري ضروري .. إلي في سكشن 2

دكتورة الاب أمس شرحت Assignment 2 وكتبت على سبورة تكملة جدول
Sample input/output ..وطبعاً شرح أساينمت .. لي كتب لي على سبورة

ما مداني أكتبه ..

ينزله وبكون شاكر له
​
output will be
ID: 20081234
Name: Student1
Grades (descending): 10 9 8 7 6.5 5.5 4.5 3.5 2.5 1.5
Top 5 grades: 10 9 8 7 6.5
Average of Grades:
Numbers above average:
Enter old value to replace:
Enter new value:
Grades after replacing:
​
 
PHP:
#include<iostream>
#include<string>
 using namespace std;
 struct bookType
 {
 string title;
 float price;
 int c;
 };
 void ReadOnebook (bookType &book)
 {
 cout << "Enter Book Title: " ;
 cin >> book.title;
 cout << "Enter Book price: " ;
 cin >> book.price;
 cout << "Enter Number of copies : " ;
 cin >> book.c;
 cout << endl;
 }
 void OutputOnebook(bookType book)
 {
 cout << " Book Title: " << book.title;
 cout << " Book price: " << book.price;
 cout << " Number of copies: " << book.c;
 cout << endl;
 }
 void outofstock (bookType book[],int num)
 {
  for(int i=0;i<num;i++)
 if(book[i].c == 0)
 cout << "Zero copies " << book[i].title << endl; 
}

 int main()
 {
 int NOB;
 bookType S[100];
 cout << "Enter the number of books ";
 cin >> NOB;
 for(int i=0;i<NOB;i++)
 ReadOnebook (S[i]);
 for(int i=0;i<NOB;i++)
 OutputOnebook (S[i]);

 outofstock(S,NOB);
 return 0;
 }

حلو بس حبيت اضيف شغله من بعد اذنكم

في int main
يفضل تسوين جيك اذا عدد الكتب اللي دخلها اليوزر اعلى من الأراي يوقف البرنامج

so it will be
PHP:
 int main()
 {
int NOB;
 bookType S[100];
 cout << "Enter the number of books ";
 cin >> NOB;
 
 if(NOB <= 100) // use this condition
 {
 for(int i=0;i<NOB;i++)
 ReadOnebook (S[i]);
 
 for(int i=0;i<NOB;i++)
 OutputOnebook (S[i]);


 outofstock(S,NOB);
}
 else
    cout<<"Invalid"<<endl;

 system("pause");
 return 0;
 }


 
شنو فكرته هذا السؤال ممكن شرح مبسط عن فكرته
راح احاوال أسويه وشوفي شغلي بعدين:smile:
Write a function deleteAllZeros which takes an array and its length. Your function should find and delete all zeros in the arrayvoid DeleteAllZeros(int list[],int &length,int maxsize);
​
 
^^^^

البرنامج يبي منك أنك تبحث في Array عن الأصفار و يحذفهم ..
​
 
التعديل الأخير:
شنو فكرته هذا السؤال ممكن شرح مبسط عن فكرته
راح احاوال أسويه وشوفي شغلي بعدين:smile:
Write a function deleteAllZeros which takes an array and its length. Your function should find and delete all zeros in the arrayvoid DeleteAllZeros(int list[],int &length,int maxsize);
​

نفرض عندنا list فيها
5,4,7,8,9,0,1,0,4,0,4
اذا سوينا call للfunction يصبح شكلها الجديد
5,4,7,8,9,1,4,4

الZero كلهم سوينا ليهم Delete

الفكره بسيطه ، تبحث عن الزيرو ، وتسوي ال Shifting to left

ننتظر نشوف محاولتك ، حتى لو غلط خله وبنعدل لك
 

نفرض عندنا list فيها
5,4,7,8,9,0,1,0,4,0,4
اذا سوينا call للfunction يصبح شكلها الجديد
5,4,7,8,9,1,4,4

الZero كلهم سوينا ليهم Delete

الفكره بسيطه ، تبحث عن الزيرو ، وتسوي ال Shifting to left

ننتظر نشوف محاولتك ، حتى لو غلط خله وبنعدل لك


اوكي بشوفه بس يمكن shifting to left مابعرفها عدل عدلوها لي :shiny:
 
شوفوه اوكي :smile2:

كود:
void deleteallzearoes(int list[], int&length)
{
for (int i=0 ; i<length ; i++ )
if(list[i]==0)
for (int j=i ; j <length ; j++)
list [j]=list[j+1];
length--;
i--
}


مو متأكد من الحل شوفوه ليي
هلي يحتاج بارت ثاني حق الفنكشن او المين ؟
 
شوفوه اوكي :smile2:

كود:
void deleteallzearoes(int list[], int&length)
{
for (int i=0 ; i<length ; i++ )
if(list[i]==0)
for (int j=i ; j <length ; j++)
list [j]=list[j+1];
length--;
i--
}


مو متأكد من الحل شوفوه ليي
هلي يحتاج بارت ثاني حق الفنكشن او المين ؟

اوكي الجواب ، بس عدلت انا شي بسيط بالنسبه للاقواس
وسويت لك برنامج كامل للTest

PHP:
#include<iostream>
#include<fstream>

void deleteallzearoes(int list[], int&length)
{
     int loc;
for (int i=0 ; i<length ; i++ )
if(list[i]==0)
{
for (int j=i ; j <length ; j++)
list [j]=list[j+1];
length--;
i--;
}

}
using namespace std;
int main()
{
    
    int list[10]={10,0,0,10,0,14,15,17,18,0};
    int len=10;
    
    deleteallzearoes(list,len);
    
    for (int i=0 ; i<len ; i++ )
cout<<list[i]<<" ";

    system("pause");
    return 0;
}

نسألكم الدعاء
 
Write a C++ program that includes the following functions:
(1) A function named sortList that takes as parameters: an array of double and the array size. The function should sort the numbers in a descending order. Use selection sort algorithm.

(2) A function named readList that takes as parameters: an array of double and the array size. The function should prompt the user to input the array data.

(3) A function named printList that takes as parameters: an array of double and the array size. The function should display the elements of the array.

(4) A function named print topFive that takes as parameters: an array of double and the array size. The function should print the largest five numbers in the array. Hint: you have to sort the array first.


Write a main program that prompts the user to enter his ID, name and 10 double numbers representing his quiz grades of ITCS104. Using the above functions, the program should generate a report as follow:
Enter Student ID: 20081234
Enetr Student Name: Student1
Enter quiz grades: 1.5 2.5 6.5 4.5 10 9 8 7 3.5 5.5


Report

ID: 20081234
Name: Student1
Grades (descending): 10 9 8 7 6.5 5.5 4.5 3.5 2.5 1.5
Top 5 grades: 10 9 8 7 6.5

الحل

#include <iostream>
using namespace std;
const int size=10;
//(1) A function named sortList that takes as parameters: an array of
// double and the array size. The function should sort the numbers in
// a descending order. Use selection sort algorithm.
void selectionSort(double list[], int length)
{
int index, smallestIndex, minIndex;
double temp;
for(index = 0; index<length; index++)
{ //step a
smallestIndex = index;
for(minIndex = index; minIndex<length; minIndex++)
if (list[minIndex] > list[smallestIndex])
smallestIndex = minIndex;
//step b
temp = list[smallestIndex];
list[smallestIndex] = list[index];
list[index] = temp;
}
}
//(2) A function named readList that takes as parameters: an array of double
// and the array size. The function should prompt the user to input the array data.
void readList( double list[],int &length)
{
cout<<"Enter the size of the array:";
cin>>length;
cout<<"Enter the array element:";
for(int i=0;i<length;i++)
cin>>list;

}
//(3) A function named printList that takes as parameters: an array of double
// and the array size. The function should display the elements of the array.

void printList( double list[],int &length)
{
for(int i=0;i<length;i++)
cout<<list<<"\t";
cout<<endl;
}
//(4) A function named print topFive that takes as parameters: an array of
//double and the array size. The function should print the largest five numbers
//in the array. Hint: you have to sort the array first.
void topFive( double list[],int &length)
{
selectionSort(list,length);
for (int i=0;i<5;i++)
cout<<list<<"\t";
}
int main()
{
double list[size] ;
int i;
int length;
readList(list,length);
selectionSort(list, length);
printList(list,length);
topFive(list,length);
system("pause");
}

بليز في احد يساعدني في الجزء الثاني

Complete the previous exercise to include the following functions:
(1) A function named computeAverage that takes as parameters: an array of double and the array size. The function should calculate and return the average of the double numbers in the array.

(2) A function named displayAboveAverage that takes as parameters: an array of double and the array size. The function should display the numbers in the array that are above the average. Hint: call computeAverage to find the average of the numbers.

(3) A function named countGrade that takes as parameters: an array of double, the array size, a double value (oldValue), and a double value (newValue). The function should replace each occurrence of the oldValue by the newValue.


Write a main program to test your functions.
 
اوكي الجواب ، بس عدلت انا شي بسيط بالنسبه للاقواس
وسويت لك برنامج كامل للTest

PHP:
#include<iostream>
#include<fstream>

void deleteallzearoes(int list[], int&length)
{
     int loc;
for (int i=0 ; i<length ; i++ )
if(list[i]==0)
{
for (int j=i ; j <length ; j++)
list [j]=list[j+1];
length--;
i--;
}

}
using namespace std;
int main()
{
    
    int list[10]={10,0,0,10,0,14,15,17,18,0};
    int len=10;
    
    deleteallzearoes(list,len);
    
    for (int i=0 ; i<len ; i++ )
cout<<list[i]<<" ";

    system("pause");
    return 0;
}

نسألكم الدعاء

اي اوكي ضبط البرنامج
تسلم ماتقصر ...:smile:
 
Complete the previous exercise to include the following functions:
(1) A function named computeAverage that takes as parameters: an array of double and the array size. The function should calculate and return the average of the double numbers in the array.

(2) A function named displayAboveAverage that takes as parameters: an array of double and the array size. The function should display the numbers in the array that are above the average. Hint: call computeAverage to find the average of the numbers.

(3) A function named countGrade that takes as parameters: an array of double, the array size, a double value (oldValue), and a double value (newValue). The function should replace each occurrence of the oldValue by the newValue.
PHP:
double computeAverage(double list[],int length)
{
    double A=0;
    for(int index=0;index<length;index++)
        A=A+list[index];
    double Average=A/length; 


    return Average;

}

PHP:
void displayAboveAverage(double list[],int length)
{
    for(int index=0;index<length;index++)
        if(list[index]>computeAverage(list,length))
            cout<<list[index]<<" ";
        
}
PHP:
void countGrade(double list[],int length,double oldValue,double newValue)
{

    for(int index=0;index<length;index++)
    {
        if(list[index]== oldValue)
            list[index]= newValue;
    }
    for(int index=0;index<length;index++)
        cout<<list[index]<<" ";

}

هذي الFunctions الناقصه

اما جزء الTest أقصد اللي في الmain
هذا حاولي فيه ، عشان تستفيدين
واذا صارت صعوبات خلي الكود اللي وصلتين له وبنشوف

نسألكم الدعاء
 
هذي main اللي سويتها
شنو الخلل اللي فيها ؟

PHP:
 int main()
{
double list[size],length , Average ,oldValue ,newValue;
int i ;
computeAverage(list,length);
displayAboveAverage(list,length);
countGrade(list,length,oldValue,newValue);
cout<<Average<<"\t";
cout<<endl;
return 0 ;
}
 
هذي main اللي سويتها
شنو الخلل اللي فيها ؟

PHP:
 int main()
{
double list[size],length , Average ,oldValue ,newValue;
int i ;
computeAverage(list,length);
displayAboveAverage(list,length);
countGrade(list,length,oldValue,newValue);
cout<<Average<<"\t";
cout<<endl;
return 0 ;
}
امم جاوبي على هالأسئلة وبتعرفين الخطأ
1- وين القيم الافتراضيه للأراي ؟؟
2- هل الlength نوعه double؟
3- عرفتين average ونوعه double
ومباشره بدون عمليات حسابيه قلتين cout>>avreage;
هل الfunction نوعها return ؟
 
عودة
أعلى أسفل