Write the definition of a function AddUp(int Arr[], int N) in C++, in which all even positions (i.e. 0,2,4,...) of the array should be added with the content of the element in the next position and odd positions (i.e. 1,3,5,...) elements should be incremented by 10.
Example: if the array Arr contains
23 | 30 | 45 | 10 | 15 | 25 |
53 | 40 | 55 | 20 | 40 | 35 |
NOTE:
● The function should only alter the content in the same array.
● The function should not copy the altered content in another array.
● The function should not display the altered content of the array.
● Assuming, the Number of elements in the array are Even.
void AddUp(int Arr[], int N)
{
for(int i=0; i<N; i++)
{
if(i%2==0){
Arr[i]=Arr[i]+Arr[i+1];
}else{
Arr[i]=Arr[i]+10;
}
}
}
Write a definition for a function SUMMIDCOL(int MATRIX[][10],int N,int M) in C++, which finds the sum of the middle column’s elements of the MATRIX (Assuming N represents a number of rows and M represents number of columns, which is an odd integer).
Example: if the content of array MATRIX having N as 5 and M as 3 is as follows:
1 | 2 | 1 |
2 | 1 | 4 |
3 | 4 | 5 |
4 | 5 | 3 |
5 | 3 | 2 |
The function should calculate the sum and display the following:
Sum of Middle Column: 15
ARR[15][20] is a two-dimensional array, which is stored in the memory along the row with each of its elements occupying 4 bytes. Find the address of the element ARR[5][15], if the element ARR[10][5] is stored at the memory location 35000.
Write the definition of a member function PUSHGIFT() for a class STACK in C++,to add a GIFT in a dynamically allocated stack of GIFTs considering the following code is already written as a part of the program:
struct GIFT
{
int GCODE; //Gift Code
char GDESC[20]; //Gift Description
GIFT *Link;
};
class STACK
{
Gift *TOP;
public:
STACK(){
TOP=NULL;
}
void PUSHGIFT();
void POPGIFT();
~STACK();
};
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion:
X - ( Y + Z ) / U * V
Polina Raj has used a text editing software to type some text in an article. After saving the article as MYNOTES.TXT, she realised that she has wrongly typed alphabet K in place of alphabet C everywhere in the article.
Write a function definition for PURETEXT() in C++ that would display the corrected version of the entire article of the file MYNOTES.TXT with all the alphabets 'K' to be displayed as an alphabet 'C' on screen.
Note: Assuming that MYNOTES.TXT does not contain any C alphabet otherwise.
Example:
If Polina has stored the following content in the file MYNOTES.TXT:
I OWN A KUTE LITTLE KAR.
I KARE FOR IT AS MY KHILD.
The function PURETEXT() should display the following content:
I OWN A CUTE LITTLE CAR.
I CARE FOR IT AS MY CHILD.
Write a definition for function COUNTPICS ( ) in C++ to read each object of a binary file PHOTOS.DAT, find and display the total number of PHOTOS of type PORTRAIT. Assume that the file PHOTOS.DAT is created with the help of objects of class PHOTOS, which is defined below:
class PHOTOS
{
int PCODE;
char PTYPE[20]; //Photo Type as “PORTRAIT”,”NATURE”
public:
void ENTER()
{
cin>>PCODE;gets(PTYPE);
}
void SHOWCASE()
{
cout<<PCODE<<":"<<PTYPE<<endl;
}
char *GETPTYPE(){
return PTYPE;
}
};
Find the output of the following C++ code considering that the binary file CLIENTS.DAT exists on the hard disk with a data of 200 clients.
class CLIENTS
{
int CCode;char CName[20];
public:
void REGISTER();
void DISPLAY();
};
void main()
{
fstream File;
File.open("CLIENTS.DAT", ios::binary | ios::in);
CLIENTS C;
File.seekg(6*sizeof(C));
File.read((char*)&C, sizeof(C));
cout<<"Client Number:"<<File.tellg()/sizeof(C) + 1;
File.seekg(0, ios::end);
cout<<" of "<<File.tellg()/sizeof(C)<<endl;
File.close();
}