Write the definition of a function Reverse(int Arr[], int N) in C++, which should reverse the entire content of the array Arr having N elements, without using any other array.
Example: if the array Arr contains
13 | 10 | 15 | 20 | 5 |
Then the array should become
5 | 20 | 15 | 10 | 13 |
NOTE:
Write a definition for a function ADDMIDROW(int MAT[][10], int R, int C) in C++, which finds sum of the middle row elements of the matrix MAT (Assuming C represents the number of Columns and R represents the number of rows, which is an odd integer).
For example, if the content of array MAT having R as 3 and C as 5 is as follows:
1 | 2 | 3 | 4 | 5 |
2 | 1 | 3 | 4 | 5 |
3 | 4 | 1 | 2 | 5 |
The function should calculate the sum and display the following:
Sum of Middle Row: 15
T[25][30] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 2 bytes, find the address of the element T[10][15], if the element T[5][10] is stored at the memory location 25000.
Write the definition of a member function ADDMEM() for a class QUEUE in C++, to add a MEMBER in a dynamically allocated Queue of Members considering the following code is already written as a part of the program.
struct Member
{
int MNO;
char MNAME[20];
Member *Next;
};
class QUEUE
{
Member *Rear,*Front;
public:
QUEUE(){Rear=NULL;Front=NULL;}
void ADDMEM();
void REMOVEMEM();
~QUEUE();
};
void QUEUE::ADDMEM()
{
Member *T;
T=new Member;
cin>>T->MNO;
gets(T->MNAME);
T->Next=NULL;
if (Rear==NULL)
{
Rear=T;Front=T;
}
else
{
Rear->Next=T;
Rear=T;
}
}
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion.
P + ( Q - R ) * S / T
Aditi has used a text editing software to type some text. After saving the article as WORDS.TXT, she realised that she has wrongly typed alphabet 'J' in place of the alphabet 'I' everywhere in the article.
Write a function definition for JTOI() in C++ that would display the corrected version of the entire content of the file WORDS.TXT with all the alphabets 'J' to be displayed as an alphabet 'I' on screen.
Note: Assuming that WORD.TXT does not contain any J alphabet otherwise.
Example: If Aditi has stored the following content in the file 'WORDS.TXT':
'WELL, THJS JS A WORD BY JTSELF. YOU COULD STRETCH THJS TO BE A SENTENCE'
The function JTOI() should display the following content:
'WELL, THIS IS A WORD BY ITSELF. YOU COULD STRETCH THIS TO BE A SENTENCE'
Write a definition for function COUNTDEPT( ) in C++ to read each object of a binary file TEACHERS.DAT, find and display the total number of teachers in the department MATHS. Assume that the file TEACHERS.DAT is created with the help of objects of class TEACHERS, which is defined below:
class TEACHERS
{
int TID; char DEPT[20];
public:
void GET()
{
cin>>TID;gets(DEPT);
}
void SHOW()
{
cout<<TID<<":"<<DEPT<<endl;
}
char *RDEPT(){return DEPT;}
};
Find the output of the following C++ code considering that the binary file BOOK.DAT exists on the hard disk with a data of 200 books.
class BOOK
{
int BID;char BName[20];
public:
void Enter();void Display();
};
void main()
{
fstream InFile;
InFile.open("BOOK.DAT",ios::binary|ios::in);
BOOK B;
InFile.seekg(5*sizeof(B));
InFile.read((char*)&B, sizeof(B));
cout<<"Book Number:"<<InFile.tellg()/sizeof(B) + 1;
InFile.seekg(0,ios::end);
cout<<" of "<<InFile.tellg()/sizeof(B)<<endl;
InFile.close();
}