You are on page 1of 14

# Question 1 A.

void main() { int j = 17; int a[4] = { 1 , 2, 3 , 4 }; int k = 18; printArray(a,4); a[3] = j; printArray(a,4); a[-1] = 98; a[4] = 101; printArray(a,4); cout << "j = " << j << "\n"; cout << "k = " << k << "\n"; printArray(a,5); printArray(a-1,6); }

( . "a[4] = 101;"± "a[-1] = 98" ±

. ). .

, . ±

. . .

/*
{ 1 , 2 , 3 , 4 ,} { 1 , 2 , 3 , 17 ,} { 1 , 2 , 3 , 17 ,} j = 17 k = 18 { 1 , 2 , 3 , 17 , 101 ,} { 98 , 1 , 2 , 3 , 17 , 101 ,} Press any key to continue . . . */

i++) // loop to fill the set. { cout<<"Enter number? \n ". i. { if(arr[i]==minimum) cout<<i<<" . { if (arr[i]<minimum) minimum=arr[i].i++) // printing the places in the set of minimum value. () arr[NUMBER]. i<NUMBER . int const void main { int int NUMBER=20. cin>>arr[i] . minimum.Question 2 #include<iostream> using namespace std. for (i=0 . } /**********OUTPUT*************** Enter number? 1 Enter number? 2 Enter number? 3 Enter number? 4 Enter number? 5 Enter number? 6 Enter number? 7 Enter number? 8 Enter number? 8 Enter number? 9 Enter number? 9 Enter number? 8 . } minimum=arr[0]. i++) // loop to find the minimum number. " . for(i=0. i<NUMBER . for (i=0. i<NUMBER. } cout<<endl<<"The places in the set where the minimum number "<<minimum<<" appear are : " . } cout<<endl.

. ************************/ . .Enter 7 Enter 6 Enter 5 Enter 4 Enter 3 Enter 1 Enter 0 Enter 6 number? number? number? number? number? number? number? number? The places in the set where the minimum number 0 appear are : 18 . Press any key to continue .

) \n" . { cout<<"Enter number? \n ". adowncounter=1.Question 3 #include<iostream> using namespace std. // stop the loop if the input is -1. { if (arr[i]>=arr[i+1]) { adowncounter++. i<NUMBER . } } cout<<"Starting from index "<<AindexOfMin<<" the biggest serial which goes down (contains of "<<temp<<" values. if (arr[i]==-1) { size=i . } /*************OUTPUT************** Enter number? 5 Enter number? 3 Enter number? 1 Enter number? 4 Enter number? 6 Enter number? 4 Enter number? 3 . } } for(i=0. } } else { adowncounter=0. int i. // calculate the members in down serial of input numbers. int const NUMBER=50. i++) // loop to fill the set. temp=0. AindexOfMin. i<size . AindexOfMin= i-temp+1 . and check out what is the index before the serial. void main() { int arr[NUMBER]. if (temp<adowncounter) { temp=adowncounter. i++) // loop to compare the numbers . cin>>arr[i] . size. found out what lenth of the biggest serial which goes down . for(i=0. break.

) Press any key to continue .Enter number? 2 Enter number? -1 Starting from index 4 the biggest serial which goes down (contains of 4 values. **************/ . . .

in addition will sort the numbers by odd numbers after th even numbers.4}. temp . function will copy all the Odd numbers from A-array to B-array. int size) { int i. res=NumberOfPositiveValues(arr. i<size . // C.2.int size) // A { int i.0. i++) { if (arr[i]>0) { index++.1. i2.size ) . }//if }//for return index. will return the number of even numbers in A. size). // example int B[8]={0}.3. int size) // B { int res. //D. for (i=0. i++) { if (A[i]%2!=0) { B[i]=A[i]. } } OutputNumOfPosValues(B . // B. int size). // calling for the previouse function } void removeOdd (int A[].array. i<sizeA. index=0. void copyOdd (int A[]. void main() { int A[8]={0.Question 4 #include<iostream> using namespace std. int B[]. int size). E. int size=8. } void copyOdd (int A[]. int NumberOfPositiveValues (int arr[]. int B[].2. for (i=0. for(i=0. function receive array. int sizeA. int sizeA. // returns the count of numbers bigger than 0 void OutputNumOfPosValues (int arr[]. } void OutputNumOfPosValues (int arr[]. int& sizeB) // C { int i. // A .i++) { .8). removeOdd(A . cout<<res<<endl . int size). int& sizeB) . } int NumberOfPositiveValues (int arr[]. void removeOdd (int A[]. i<size.1.

0 . i2++) { if (A[i2]%2==0) { temp=A[i2]. " . 2 . 3 . for(i=0. new size is: 5 Press any key to continue . break. 1 . } } cout<<"new size is: " <<size<<endl . } /* 0 . */ . i<size. 1 . i<size. A[i]=temp. i2<size. i++) { if (A[i]%2!=0) { size=i.i++) { cout<<A[i]<<" . . . 2 . } } } } for(i=0. } cout<<endl. A[i2]=A[i]. break.if (A[i]%2!=0) { for (i2=i+1. 4 .

} case '}' : { i++. //prototype declaration bool goodBracket(char []). break. break. } case '\n' : . } case ']' : { i++. break. break. int i=0. else cout << "Bracket value is bad\n".Question 6 #include <iostream > using namespace std. bool enterKey=false. if (getData(brackets)) if (goodBracket(brackets)) cout << "Bracket value is good\n". } case ')' : { i++. } case '[' : { i++. while ((good) && (i<=SIZE-1) && !enterKey) { brackets[i]=cin. //Global constants const int SIZE= 60. break. const int DEPTH=30. } bool getData(char brackets[]) { bool good=true. switch (brackets[i]) { case '(' : { i++. break. } case '{' : { i++. else cout << "Invalid input!\n". bool getData(char[]). terminated by enter:\n".get(). cout << "Please enter a series of brackets. void main() { char brackets[SIZE].

break. break. lastBracketIndex++. lastBracketIndex++. char lastBracket=' '. } case '(' : { openArr[lastBracketIndex]=brackets[i]. i++. } bool goodBracket(char brackets[]) { char openArr[DEPTH]. break.numOfClosed=0. break. i++. i++. } default: { good=false. numOfOpen++. int i=0. } case '[' : { openArr[lastBracketIndex]=brackets[i]. return false. numOfOpen++. break. numOfOpen++. int numOfOpen=0. lastBracketIndex++. int lastBracketIndex=0. bool good=true. } case ')' : . while ((i<=SIZE-1) && (good)) { switch (brackets[i]) { case '{' : { openArr[lastBracketIndex]=brackets[i].{ enterKey=true. } } } return good.

. numOfClosed++. terminated by enter: (()) Bracket value is good Press any key to continue . /*******************OUTPUTS************** 1)Please enter a series of brackets.{ if (openArr[lastBracketIndex-1]=='(') { lastBracketIndex--. break. numOfClosed++. } default: { } } } if (numOfOpen==numOfClosed) return good. } i=SIZE. break. } else good=false. i++. i++. break. . } case '}' : { if (openArr[lastBracketIndex-1]=='{') { lastBracketIndex--. numOfClosed++. } case ']' : { if (openArr[lastBracketIndex-1]=='[') { lastBracketIndex--. break. else return false. . } else good=false. i++. } else good=false.

. . ********************************************/ . terminated by enter: ([])(){} Bracket value is good Press any key to continue . 6)Please enter a series of brackets. terminated by enter: ({)} Bracket value is bad Press any key to continue . . terminated by enter: ([]{} Bracket value is bad Press any key to continue . . 5)Please enter a series of brackets. terminated by enter: ([{()[]}]){()} Bracket value is good Press any key to continue . 7)Please enter a series of brackets. . . . terminated by enter: ([()]) Bracket value is good Press any key to continue . 3)Please enter a series of brackets. 4)Please enter a series of brackets. . . . .2)Please enter a series of brackets. . terminated by enter: ({[])} Bracket value is bad Press any key to continue .