Define a class RESTRA in C++ with following description: Private Members:
A member function GetSticker() to assign the following values for Sticker as per the given Ftype:
FType |
Sticker |
Vegetarian |
GREEN |
Contains Egg |
YELLOW |
Non-Vegetarian |
RED |
Public Members :
Answer the questions (i) to (iv) based on the following:
class COMPANY
{
char Location[20]; double Budget,Income;
protected:
void Accounts( ); public:
COMPANY();
void Register( ); void Show( );
};
class FACTORY: public COMPANY
{
char Location[20];
int Workers;
protected:
double Salary;
void Computer();
public:
FACTORY();
void Enter( );
void show( );
};
class SHOP: private COMPANY
{
char Location[20];
float Area;
double Sale;
public:
SHOP();
void Input();
void Output();
};
(i) Name the type of inheritance illustrated in the above C++ code. |
(ii) Write the names of data members, which are accessible from member functions of class SHOP. |
(iii) Write the names of all the member functions, which are accessible from objects belonging to class FACTORY. |
(iv) Write the names of all the members, which are accessible from objects of class SHOP. |
Write a function SWAP2BEST (int ARR[], int Size) in C++ to modify the content of the array in such a way that the elements, which are multiples of 10 swap with the value present in the very next position in the array.
For example:
If the content of array ARR is 90,56,45,20,34,54
The content of array ARR should become 56,90,45,34,20,54
An array T[20][10] is stored in the memory along the column with each of the element occupying 2 bytes, find out the memory location of T[10][5], if an element T[2][9] is stored at location 7600.
Write a function ALTERNATE (int A[][3],int N,int M) in C++ to display all alternate element from two-dimensional array A (starting from A[0][0]).
For example:
If the array is containing:
23 | 54 | 76 |
37 | 19 | 28 |
62 | 13 | 19 |
The output will be:
23 | 76 | 19 | 62 | 19 |
Observe the program segment given below carefully and the question that follow:
class Stock
{
int Ino,Qty; char Item[20];
public:
void Enter() {cin>>In0;gets(Item); cin>>Qty;}
void Issue(int Q) { Qty+=Q}
void Purchase(int Q) { Qty-=Q}
int GetIno(return Ino;)
};
void Purchaseitem(int Pino, int PQty)
{
fstream file;
File.open("STOCK.DAT",ios::binary|ios::in|ios::out);
Stock S;
int Success=0;
while (Success==0 && File.read((char*)&S, sizeof(S)))
{
if (Pino==S.GetIno())
{
S.Purchase(PQty);
File.seekp(Success); //Statement 1
File.write((char*) &S, sizeof(S)); //statement 2
Success++;
}
}
if (Success==1)
cout<<"Purchase Updated"<<endl;
else
cout<<"Wrong Item No"<<endl;
File.close( );
}
(i) Write statement 1 to position the file pointer to the appropriate place, so that the data updation is done for the required item.
(ii) Write statement 2 to perform the write operation so that the updation is done in the binary file.
Write a function in C++ to read the content of a text file 'DELHI.TXT' and display all those lines on the screen, which are either starting with ‘D’ or starting with ‘M’.
#include<fstream.h>
#include<conio.h>
int main()
{
ifstream fin;
fin.open('out.txt');
char str[80];
int count=0;
clrscr();
while(!fin.eof())
{
fin.getline(str,80);
if(str[0]=='D' || str[0]=='M')
{
cout<<str<<endl;
}
count++;
}
cout<<'Number of lines in file is '<<count; fin.close();
getch();
return 0;
}
Write a function in C++ to search for the details (Phoneno and Calls) of those Phones, which have more than 800 calls from a binary file “phones.dat”. Assuming that this binary file contains records/objects of class Phone, which is defined below.
class Phone
{
char Phoneno[10]; int Calls;
public:
void Get( )
{
gets(Phoneno); cin>>Calls;
}
void Billing( )
{
cout<<Phoneno<<'#'<<Calls<<endl;
}
int GetCalls( )
{
return Calls;
}
};
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: