Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

)‫ נקודות‬20( 1 ‫שאלה‬

)‫ נקודות‬3( .'‫סעיף א‬
template <class T> class MinStack {
private:
Stack<T> stValue;
Stack<T> stMin;
T min;

public:
MinStack();
~MinStack();
bool isEmpty() const ;
bool push(const T&);
void pop(T & );
T Min();
};
)‫ נקודות‬2( .'‫סעיף ב‬
MinStack() { } // Default Constructor
~MinStack() { }

)‫ נקודוה‬1( .'‫סעיף ג‬
bool isEmpty() const {
return stValue.isEmpty();
}

)‫ נקודות‬6( .'‫}סעיף ד‬
bool push(const T& pushValue) {
if (stValue.isEmpty()) {
stValue.push(pushValue);
stMin.push(pushValue);
min = pushValue;
return true;
}
if (stValue.push(pushValue)) {
if (pushValue < min) {
min = pushValue;
stMin.push(pushValue);
}
else
stMin.push(min);
return true;
}
else
return false;
}
)‫ נקודות‬3( .'‫סעיף ה‬
void pop(T & popValue) throw(const char *) {
if (stValue.pop(popValue))
stMin.pop(min);
else
throw "pop failure";
}
)‫ נקודה‬1( .'‫סעיף ו‬
T Min() {
return min;
}

1
)‫ נקודות‬4( .'‫סעיף ז‬
int main() {
MinStack<int> m; //m is a min stack of ints
int arr[5] = { 1,-2,3 };
try {
cout << m.isEmpty() << endl;
m.push(arr[0]);
cout << m.isEmpty() << m.Min() << endl;
m.push(arr[1]);
cout << m.isEmpty() << m.Min() << endl;
m.pop(arr[2]);
cout << m.isEmpty() << m.Min() << endl;
m.pop(arr[3]);
cout << m.isEmpty() << m.Min() << endl;

for (int i = 0; i < 4; i++)


cout << arr[i];
cout << endl;

m.pop(arr[4]); // empty stack : exception thrown


cout << m.isEmpty() << m.Min() << endl;
}
catch (char* e) {
cout << "Exception: " << e << endl;
}
return 0;
}
)‫ נקודות‬20( 2 ‫שאלה‬
)‫ נקודות‬4( .'‫סעיף א‬
.‫ משתנה קבוע צריך להיות מאותחל בשורת איתחול‬:‫שגיאת קומפילציה‬
)‫ נקודות‬4( .'‫סעיף ב‬
done
)‫ נקודות‬4( .'‫סעיף ג‬
C Ctor
A Ctor
B Ctor
D Ctor
)‫ נקודות‬4( .'‫סעיף ד‬
1 2 1
)‫ נקודות‬4( .'‫סעיף ה‬
.private ‫ שמוגדר‬m_x ‫ אין גישה לשדה‬draw ‫ במתודה‬:‫שגיאת קומפילציה‬

2
)‫ נקודות‬18( 3 ‫שאלה‬

1. A Ctor )'‫ נק‬1( D Dtor


A CCtor C Dtor
A Dtor A Dtor
AError B Dtor
A Dtor A Dtor

2. A Ctor )'‫ נק‬3( 7. A Ctor )'‫ נק‬3(


B Ctor B Ctor
A Ctor A Ctor
B CCtor C Ctor
B Dtor D Ctor
A Dtor A Ctor
AError B Ctor
B Dtor A Ctor
A Dtor C Ctor
3. A Ctor )'‫ נק‬2( D CCtor
B Ctor D Dtor
A CCtor C Dtor
A CCtor A Dtor
A Dtor B Dtor
B Dtor A Dtor
A Dtor DError
AError D Dtor
A Dtor C Dtor
A Dtor
4. Compilation Error!)'‫ נק‬1( B Dtor
A Dtor
5. A Ctor )'‫ נק‬2(
A Ctor 8. Compilation Error! )'‫ נק‬1(
B Ctor
A op 9. A Ctor )'‫ נק‬3(
A CCtor B Ctor
B Dtor C Ctor
A Dtor D Ctor
A Dtor A CCtor
AError A CCtor
A Dtor A Dtor
D Dtor
6. A Ctor )'‫ נק‬2( C Dtor
B Ctor B Dtor
A Ctor A Dtor
C Ctor AError
D Ctor A Dtor
DError

3
)‫ נקודות‬20( C ‫ שפת‬4 ‫שאלה‬

void rebuild(item* list1, item* list2, int num){


item *temp ,*temp2;
if(!list1 || !list2) return;
while( list1 ){
if( list1->value == num ){
list1->value = list2 ->value ;
temp2 = list1 ->next ;
for(temp= list2->next; temp; temp = temp ->next){
list1 ->next = (item*)malloc(sizeof(item));
list1 = list1 -> next ;
list1 -> value = temp -> value ;
}
list1 -> next = temp2 ;
}
list1 =list1 -> next ;
}
}

)‫ נקודות‬25 ( C ‫ שפת‬5 ‫שאלה‬

int schedule(FILE *all, FILE *options, int arr[7][24], char *filename) {


FILE *possible;
char name[21];
int courseA, courseO, day, start, finish, points, i, result=0;

if (!(possible = fopen(filename, "w"))) return -1;

while (fscanf(options, "%8d%2d%*9c", &courseO, &points) != EOF) {


do {
fscanf(all, "%20[^\n]%8d%1d%2d%2d%*9c",
name, &courseA, &day, &start, &finish);
} while (courseA != courseO);

for (i = start; i<finish && !arr[day][i]; i++);

if (i == finish) {
fprintf(possible, "%s%08d%02d%1d%02d%02d\n",
name, courseA, points, day, start, finish);
result++;
}
}

if (fclose(possible) == EOF)
return -1;

return result;
}

You might also like