Sponsor Area
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
void SUMMIDCOL(int MATRIX[ ][10], int N, int M)
{
int j, SUM=0;
j=M/2;
for(int i=0; i<N;i++){
SUM += MATRIX[i][j];
cout<<'SUM of Middle Column :'<<SUM;
}
}
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.
ROW MAJOR:
Loc(ARR[I][J]) =BaseAddress + W [( I – LBR)*C + (J – LBC)]
(where W=size of each element = 4 bytes, R=Number of
Rows=15, C=Number of Columns=20 )
Assuming LBR = LBC = 0
LOC(ARR[10][5])
35000 = BaseAddress + W(I*C + J)
35000 = BaseAddress + 4(10*20 + 5)
35000 = BaseAddress + 4(205)
35000 = BaseAddress + 820
BaseAddress = 35000 - 820
= 34180
LOC(ARR[5][15])= BaseAddress + W(I*C + J)
= 34180 + 4(100 + 15)
= 34180 + 4 x 115
= 34180 + 460
= 34640
Write function definition for WORD4CHAR() in C++ to read the content of a text file FUN.TXT, and display all those words, which has four characters in it.
Example:
If the content of the file fun.TXT is as follows:
When I was a small child, I used to play in the garden
with my grand mom. Those days were amazingly funful
and I remember all the moments of that time
The function WORD4CHAR() should display the following:
When used play with days were that time
void WORD4CHAR()
{
ifstream Fil;
Fil.open(FUN.TXT);
char W[20];
Fil>>W;
while(!Fil.eof())
{
if ((strlen(W)) == 4){
cout<<W<< ;
}
Fil>>W;
}
Fil.close();
}
Write a definition for function BUMPER( ) in C++ to read each object of a binary file GIFTS.DAT, find and display details of those gifts, which has remarks as “ÖN DISCOUNT”. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below:
class GIFTS
{
int ID;char Gift[20],Remarks[20]; float Price;
public:
void Takeonstock()
{
cin>>ID;gets(Gift);gets(Remarks);cin>>Price;
}
void See()
{
cout<<ID<<':'<<Gift<<':'<<Price<<':'<<Remarks<<endl;
}
char *GetRemarks(){return Remarks;}
}
void BUMPER()
{
GIFTS G;
ifstream fin;
fin.open(“GIFTS.DAT”, ios::binary);
while(fin.read((char*)&G, sizeof(G)))
{
if(strcmp(G.GetRemarks(), 'ON DISCOUNT')==0)
G.See();
}
fin.close();
}
Give a suitable example of a table with sample data and illustrate Primary and Alternate Keys in it.
Primary Key: Primary key is a set of one or more fields/columns of a table that uniquely identify a record in the database table. It cannot accept null, duplicate values. Only one Candidate Key can be Primary Key.
Alternate key: the Alternate key is a key that can be work as a primary key. Basically, it is a candidate key that currently is not the primary key.
Example: In below table AdmissionNo becomes Alternate Keys when we define RegistrationNo as Primary Key.
Student Registration Table:
RegistrationNo |
AdmissionNo |
Name |
Phone |
Gender |
DOB |
CBSE4554 |
215647 |
Mihir Ranjan |
9568452325 |
Male |
1992-04-15 |
CBSE6985 |
265894 |
Amita Guha |
8456985445 |
Female |
1993-03-24 |
CBSE5668 |
458961 |
Rajesh Singh |
9654212440 |
Male |
1992-12-04 |
CBSE3654 |
469799 |
Mohit Patel |
7421589652 |
Male |
1992-05-16 |
Primary Key – Registration Number
Alternate Key – Admission No
Consider the following tables CARDEN and CUSTOMER and answer (b) and (c) parts of question:
TABLE: CARDEN
Ccode |
CarName |
Make |
Color |
Capacity |
Charges |
501 |
A-Star |
Suzuki |
RED |
3 |
14 |
503 |
Indigo |
Tata |
SILVER |
3 |
12 |
502 |
Innova |
Toyota |
WHITE |
7 |
15 |
509 |
SX4 |
Suzuki |
SILVER |
4 |
14 |
TABLE: CUSTOMER
CCode |
Cname |
Ccode |
1001 |
Hemant Sahu |
501 |
1002 |
Raj Lal |
509 |
1002 |
Feroza Shah |
503 |
1004 |
Ketan Dhal |
502 |
Write SQL commands for the following statements:
Consider the following tables CARDEN and CUSTOMER and answer (b) and (c) parts of question:
TABLE: CARDEN
Ccode |
CarName |
Make |
Color |
Capacity |
Charges |
501 |
A-Star |
Suzuki |
RED |
3 |
14 |
503 |
Indigo |
Tata |
SILVER |
3 |
12 |
502 |
Innova |
Toyota |
WHITE |
7 |
15 |
509 |
SX4 |
Suzuki |
SILVER |
4 |
14 |
TABLE: CUSTOMER
CCode |
Cname |
Ccode |
1001 |
Hemant Sahu |
501 |
1002 |
Raj Lal |
509 |
1002 |
Feroza Shah |
503 |
1004 |
Ketan Dhal |
502 |
Give the output of the following SQL queries:
(i) |
COUNT(DISTINCT Make) |
(ii) |
MAX(Charges) MIN(Charges) |
(iii) |
COUNT(*) Make |
(iv) |
CarName SX4 |
Sponsor Area
Sponsor Area