EECE 230 Exam 2 with Solution, Fall 2011

American University of Beirut · Introduction to Programming · 15 pages · Dr. Ibrahim Abou Faycal · with solution

All EECE 230 files
EECE 230 Exam 2 with Solution, Fall 2011, page 1

Stuck on a question? A tutor can walk you through it.

EECE 230 Exam 2 with Solution, Fall 2011, page 2 EECE 230 Exam 2 with Solution, Fall 2011, page 3 EECE 230 Exam 2 with Solution, Fall 2011, page 4 EECE 230 Exam 2 with Solution, Fall 2011, page 5 EECE 230 Exam 2 with Solution, Fall 2011, page 6 EECE 230 Exam 2 with Solution, Fall 2011, page 7 EECE 230 Exam 2 with Solution, Fall 2011, page 8 EECE 230 Exam 2 with Solution, Fall 2011, page 9 EECE 230 Exam 2 with Solution, Fall 2011, page 10

Showing the first 10 of 15 pages. Download the PDF to see all of it.

More EECE 230 files

Show the text of this exam
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include<iostream> #include<fstream> using namespace std; void main() { ifstream input; ofstream output; char infile[100];//char array to store the name of the input file cout<<"Please enter the name of the file you want to input from:"<<endl; cin.get(infile,100); input.open(infile); output.open("OutputfFile.txt"); if(!input) cout<<"Error in reading file"<<endl; else{ int i,j; int x; for(i=0; i<5; i++) { for(j=0; j<=i; j++) { input>>x; output<<x<<" "; } output<<endl; } cout<<"Please check the outputfile"<<endl; output.close(); input.close(); } } #include<iostream> #include<cstring> using namespace std; void strAssfouri(char []); void main() { char s[500]; cout<<"Enter a string:"<<endl; cin.get(s,500);//read a line that could contain spaces max length 499 characters and store in s strAssfouri(s);//function call cout<<"Assfouri: "<<endl; cout<<s<<endl; } void strAssfouri(char s[]) { int leng=strlen(s); int i;//index for the original string char temp[500];//temporary string int tempindex=0;//index for temporary string for(i=0;i<leng;i++) { if(s[i]==' ') { temp[tempindex]=s[i]; tempindex++; } else { temp[tempindex]=s[i]; tempindex++; temp[tempindex]='s'; tempindex++; } } temp[tempindex]='\0'; strcpy(s,temp);//copy the temporary string to the initial string } #include<iostream> using namespace std; int rec10a(int [],int , int); void main() { int A[100]; int i=0; cout<<"Please enter an array of integers ending with a character:"<<endl; while(cin) { cin>>A[i]; i++; } i--;//size of array cin.clear(); cout<<"The number of integers greater than or equal to 10 is: "<<rec10a(A,0,i)<<endl; } int rec10a(int A[],int start, int end) { if(start==end) return 0;//base case to stop the recursive function else if(A[start]>=10) return (1+rec10a(A,start+1,end)); else return rec10a(A,start+1,end);//a case for A[start] is not greater or equal to 10 } #include<iostream> using namespace std; void rec10b(int [],int , int ,int &,int &); void main() { int A[100]; int n=0; int positive=0; int negative=0; cout<<"Please enter an array of integers ending with a character:"<<endl; while(cin) { cin>>A[n]; n++; } n--;//size of array cin.clear(); rec10b(A,0,n, positive, negative); cout<<"The number of integers greater than or equal to 10 is: "<<positive<<endl; cout<<"The number of integers less than or equal to -10 is: "<<negative<<endl; } void rec10b(int A[],int start, int end, int &positive, int &negative) { if(start==end)//base case to stop return; else{ if(A[start]>=10 ) positive++; else if(A[start]<=-10) negative++; rec10b(A,start+1,end,positive,negative); } } 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14