بنوته فلسطينية
Well-Known Member
- تاريخ التسجيل
- 31 ديسمبر 2010
- المشاركات
- 107
- المجموعة
- أنثى
- الدفعة الدراسية
- 2010
- الكلية
- كلية العلوم
- التخصص
- احصاء-رياضيات
اوكي يسلمو زبط معي و طلعلي الاوت بوت
اوكي يسلمو زبط معي و طلعلي الاوت بوت


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
و بالتوفيق جميعًا![]()
ههههههههمشكوور عزيزي
سويت قيت لاين انا قبل بس ما صار ما ادري ليش
... كود:#include<iostream> using namespace std; void computeAverage(double arr[],double x, int size,double avg,double sum) { avg=sum\size*1.0; cout<<"the avareg ="<<avg<<endl; } void displayAboveAverage(double arr[],double avg,int size) { double indexavg; for (int i=0;i<size;i++) if(arr[i]>avg ) { indexavg=avg; } } void countGrade(double oldvalue,double newvalue,double arr1[],double size1) { for (int i=0;i<size;i++) if(arr1[i]>avg) { oldvalue=i; newvalue=arr1[i]; } } void main () { double q1,q2,q3,q4,q5,q6,q7,q8,q9,q10, avg; long stid; string name; cout<<"enter student ID :"<<stid<<endl; cin>>stid; cout<<"enter student name :"<<name<<endl; cin>>name; cout<<"enter quiz grades:"<<endl; cin>>q1>>q2>>q3>>q4>>q5>>q6>>q7>>q8>>q9>>q10; }
هاي بارت 2 :/يطلع ايروورز ...!
void computeAverage(double arr[],double x, int size,double avg,double sum)
{
avg=sum\size*1.0;
cout<<"the avareg ="<<avg<<endl;
double computeAverage(double arr[], int size)
void displayAboveAverage(double arr[],double avg,int size)
{
double indexavg;
for (int i=0;i<size;i++)
if(arr[i]>avg )
{
indexavg=avg;
}
}
void displayAboveAverage(double arr[],int size)
void displayAboveAverage(double arr[],int size)
{
;double avg
(avg=computeAverage( arr, size
for (int i=0;i<size;i++)
if(arr[i]>avg )
{
cout<<arr[i];
}
}
void countGrade(double oldvalue,double newvalue,double arr1[],double size1){
for (int i=0;i<size;i++)
if(arr1[i]==oldvalue)
newvalue=arr1[i];
{
for (int j=0;j<size;j++)
cout<<arr1[j]<<" ";}
}

بس اخر سؤال ... كيف بدي اتأكد انو وصل الاسايمنت و اي فايلات االي لازم ابعتها؟؟
,, اني حفظت الكود بس ابي استوعبه
#include<iostream>
using namespace std;
int main()
{
int list[]={1,8,9,7,7,10,58,5,0};
int temp,min=list[0];
for (int i=0;i<9-1;i++)
{
min=i;
for (int j=i+1;j<9;j++)
{
if (list[j]<list[min])
min=j;
temp=list[min];
list[min]=list[i];
list[i]=temp;
}
}
for (int k=0;k<9;k++)
cout<<list[k]<<" ";
cout<<endl;
return 0;
}
[TABLE="align: right"]
[TR]
[TD][/TD]
[/TR]
[/TABLE]
Part#1: Lab Exercise
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:
[TABLE="align: center"]
[TR]
[TD]Sample Input/Output:[/TD]
[/TR]
[TR]
[TD]Enter Student ID: 20081234
Enter 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
[/TD]
[/TR]
[/TABLE]
Part#2: Home Assignment
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.
ممكن فقط شرح طريقة السؤال؟؟!!
#include <iostream>
#include <string>
using namespace std;
void sortlist (double x[],int y)
{
double z;
for (int i=0;i<y;i++)
{
for (int j=i+1;j<y;j++)
{
if (x[i]<x[j])
{
z=x[i];
x[i]=x[j];
x[j]=z;
}
}
}
}
void readList (double x[],int y)
{
for(int i=0;i<y;i++)
cin>>x[i];
}
void printList (double x[],int y)
{
for(int i=0;i<y;i++)
cout<<x[i]<<" ";
}
void printopFive (double x[],int y)
{
double z;
for (int i=0;i<y;i++)
{
for (int j=i+1;j<y;j++)
{
if (x[i]<x[j])
{
z=x[i];
x[i]=x[j];
x[j]=z;
}
}
}
for(int i=0;i<5;i++)
cout<<x[i]<<" ";
}
int main()
{
double quiz[10];
int id;
string name;
cout<<"Enter Student ID: ";
cin>>id;
cout<<"Enter Student Name: ";
cin>>name;
cout<<"Enter quiz grades: ";
readList(quiz,10);
cout<<"\n\nReport\nID: "<<id<<"\nName: "<<name<<endl;
cout<<"Grades (descending): ";
sortlist(quiz,10);
printList(quiz,10);
cout<<"\nTop 5 grades: ";
printopFive(quiz,10);
cout<<endl;
system("pause");
return 0;
}
#include<iostream>
using namespace std;
double computeAverage (double arr[],int x)
{
double sum=0;
for(int i=0;i<x;i++)
sum+=arr[i];
return sum;
}
void displayAboveAverage (double arr[],int x)
{
double avr=computeAverage(arr,x);
for (int i=0;i<x;i++)
if (arr[i]>x)cout<<arr[i]<<" ";
}
void countGrade(double arr[],double x,double oldv,double newv)
{
for (int i=0;i<x;i++)
if(arr[i]==oldv)arr[i]=newv;
}
int main ()
{
double arr[10],oldv,newv;
cout<<"enter quiz grades:"<<endl;
for (int i=0;i<10;i++)
cin>>arr[i];
cout<<"Avrage: "<<computeAverage(arr,10)<<endl;
cout<<"Abouve average: ";
displayAboveAverage(arr,10);
cout<<"\nEnter oldv & newv: ";
cin>>oldv>>newv;
cout<<"\nQuiz grades after change: ";
countGrade(arr,10,oldv,newv);
for (int i=0;i<x;i++)cout<<arr[i]<<" ";
cout<<endl;
system("pause");
return 0;
}
PART A
Write a function named outputarr that output the elements of an integer array.
PART B
Write a function named readarr that reads the elements of an integer array.
PART C
Write a function named
minPosition that takes an array of integers intList, and the
index of the first element in the array (start), and the size of the array. The function should return the Position (Location) of the
minimum value in the array (a number between start and size).
For example, if the following array intList :
is called with the value of start as 0 it should return 7,
44
[TD="width: 10%, bgcolor: #ffffff"] 9
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 7
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 14
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 17
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 12
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 15
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 3
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 6
[/TD]
[TD="width: 10%, bgcolor: #ffffff"] 14
[/TD]
but if it is called with the value of start as 8 it should return 8.
PARTD
Use the above function of part C to write a selectionsort function to sort an array of integers in
ascending order (low to high).
PART F
Write a main function to test the above functions.
Declare an integer array named Arr with minimum size 50.
Read 10 integers into array Arr (call function readtarr)
Output the array before sorting( call function outputarr).
Sort the array using function selectionsort
Output the array after sorting( call function outputarr).
#include <iostream>
using namespace std;
void outputarr (int x[],int y)
{
for(int i=0;i<y;i++)
cout<<x[i]<<" ";
cout<<endl;
}
void readarr (int x[],int y)
{
for(int i=0;i<y;i++)
cin>>x[i];
}
int minPosition (int intList[],int s,int y)
{
int min=intList[s],pos=s;
for (int i=s;i<y;i++)
if (intList[i]<min){min=intList[i];pos=i;}
return pos;
}
void selectionsort (int x[],int y)
{
int temp;
for (int i=0;i<y;i++)
{
temp=x[minPosition(x,i,y)];
x[minPosition(x,i,y)]=x[i];
x[i]=temp;
}
}
int main()
{
int Arr[20];
cout<<"Enter 10 numbers :\n";
readarr(Arr,10);
cout<<"Your numbers :\n";
outputarr(Arr,10);
selectionsort(Arr,10);
cout<<"Your numbers after sorting :\n";
outputarr(Arr,10);
system("pause");
return 0;
}
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.
كيف طريقة الحل ؟
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str;
int min=100,max=0;
ifstream in;in.open("names.dat");
ofstream out;out.open("namelength.dat");
if (!in){cout<<"Erorr no file";return 1;}
for(int i=0;i<10;i++)
{
in>>str;
out<<str<<" "<<str.length()<<endl;
if (str.length()<min)min=str.length();
if (str.length()>max)max=str.length();
}
cout<<"Maximum name size : "<<max<<endl;
cout<<"Maimum name size : "<<min<<endl;
system("pause");
return 0;
}
سلام عليكم شعب .. ممكن مساعدتي في الحل .. فاهمتنه بس مو عارفه اكتب البرنامج
Usingthe “String Type” functions discussed in chapter 8 (find, substr, length, swap). Write a program that prompts the user to enter a word of an odd length. Your program should check that the entered word is of an odd length.The program shouldthen scramble the word by moving the middle character to the beginning of the word and output the new word.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int mid;
do
{
cout<<"Enter a word of an odd length :\n";
cin>>str;
}while (!(str.length()%2));
mid=str.length()/2;
str=str[mid]+str.substr(0,mid)+str.substr(mid+1);
cout<<"\nNew word :\n"<<str<<endl;
system("pause");
return 0;
}

