-->

Structured Query Language

Question
CBSEENCO12011571

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

 

Solution
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;
	}
}

Some More Questions From Structured Query Language Chapter

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 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

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;}
}

Find the output of the following C++ code considering that the binary file MEM.DAT exists on the hard disk with a data of 1000 members.

class MEMBER
{
	int Mcode;char MName[20];
public:
	void Register();void Display();
};
void main()
{
	fstream MFile;
	MFile.open('MEM.DAT',ios::binary|ios::in);
	MEMBER M;
	MFile.read((char*)&M, sizeof(M));
	cout<<'Rec:'<<MFile.tellg()/sizeof(M)<<endl;
	MFile.read((char*)&M, sizeof(M));
	MFile.read((char*)&M, sizeof(M));
	cout<<'Rec:'<<MFile.tellg()/sizeof(M)<<endl;
	MFile.close();
}

Give a suitable example of a table with sample data and illustrate Primary and Alternate Keys in it.

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:

  1. To display the names of all the silver colored
  2. To display name of car, make and capacity of cars in descending order of their sitting
  3. To display the highest charges at which a vehicle can be hired from
  4. To display the customer name and the corresponding name of the cars hired by them

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:

  1. SELECT COUNT(DISTINCT Make) FROM CARDEN;
  2. SELECT MAX(Charges),MIN(Charges) FROM CARDEN;
  3. SELECT COUNT(*),Make FROM CARDEN;
  4. SELECT CarName FROM CARDEN WHERE Capacity=4;