Friday 26 August 2016

questions from IndiaBix

questions on OOP concepts

Questions

Develop a Supermarket Billing System using C++.

Develop a Supermarket Billing System using C++. The key features of this application are listed below :  Bill Report : It shows the bill report of all the items added in supermarket billing system.  Add, Remove or Edit items: With this feature one can add, remove and modify item details. In add items, one can add information or details such as item no., item name, manufacturing date, price, quantity, tax percent, and many more.  Show item details: This feature allows users to see the items and the corresponding details given for the item while adding the item. Use file to store the data.


#include<iostream>
#include<windows.h>
#include<conio.h>
#include<fstream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
using namespace std;
//global variable declaration
int k=7,r=0,flag=0;
COORD coord = {0, 0};
void gotoxy(int x, int y)
{
 COORD coord;
 coord.X = x;
 coord.Y = y;
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
struct date
{
int mm,dd,yy;
};

ofstream fout;
ifstream fin;

class item
{
int itemno;
char name[25];
date d;
public:
void add()
{
cout<<"\n Item No: ";
cin>>itemno;
cout<<"\n\n\t Name of the item: ";
cin>>name;
//gets(name);
cout<<"Manufacturing Date(dd-mm-yy): ";
cin>>d.mm>>d.dd>>d.yy;
}
void show()
{
cout<<"Item No: ";
cout<<itemno;
cout<<"Name of the item: ";
cout<<name;
cout<<"Date : ";
cout<<d.mm<<"-"<<d.dd<<"-"<<d.yy;
}

void report()
{
gotoxy(3,k);
cout<<itemno;
gotoxy(13,k);
puts(name);
}
int retno()
{
    return(itemno);
}
};

class amount:public item
{
float price,qty,tax,gross,dis,netamt;
public:
void add();
void show();
void report();
void calculate();
void pay();
float retnetamt()
{
    return(netamt);
}
}amt;

void amount::add()
{
item::add();
cout<<"Price: ";
cin>>price;
cout<<"Quantity: ";
cin>>qty;
cout<<"Tax percent: ";
cin>>tax;
cout<<"Discount percent: ";
cin>>dis;
calculate();
fout.write((char *)&amt,sizeof(amt));
fout.close();
}
void amount::calculate()
{
gross=price+(price*(tax/100));
netamt=qty*(gross-(gross*(dis/100)));
}
void amount::show()
{
fin.open("itemstore.dat",ios::binary);
fin.read((char*)&amt,sizeof(amt));
item::show();
cout<<"Net amount: ";
cout<<netamt;
fin.close();
}

void amount::report()
{
item::report();
gotoxy(23,k);
cout<<price;
gotoxy(33,k);
cout<<qty;
gotoxy(44,k);
cout<<tax;
gotoxy(52,k);
cout<<dis;
gotoxy(64,k);
cout<<netamt;
k=k+1;

if(k==50)
{
gotoxy(25,50);
cout<<"PRESS ANY KEY TO CONTINUE...";
getch();
k=7;
system("cls");
gotoxy(30,3);
cout<<" ITEM DETAILS ";
gotoxy(3,5);
cout<<"NUMBER";
gotoxy(13,5);
cout<<"NAME";
gotoxy(23,5);
cout<<"PRICE";
gotoxy(33,5);
cout<<"QUANTITY";
gotoxy(44,5);
cout<<"TAX";
gotoxy(52,5);
cout<<"DEDUCTION";
gotoxy(64,5);
cout<<"NET AMOUNT";
}
}

void amount::pay()
{
show();
cout<<"\n\n\n\t\t*********************************************";
cout<<"\n\t\t                 DETAILS                  ";
cout<<"\n\t\t*********************************************";
cout<<"\n\n\t\tPRICE                     :"<<price;
cout<<"\n\n\t\tQUANTITY                  :"<<qty;
cout<<"\n\t\tTAX PERCENTAGE              :"<<tax;
cout<<"\n\t\tDISCOUNT PERCENTAGE         :"<<dis;
cout<<"\n\n\n\t\tNET AMOUNT              :Rs."<<netamt;
cout<<"\n\t\t*********************************************";
}

int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<<setprecision(2);
fstream tmp("temp.dat",ios::binary|ios::out);
menu:
system("cls");
gotoxy(25,2);
cout<<"Super Market Billing ";
gotoxy(25,3);
cout<<"===========================nn";
cout<<"\n\t\t1.Bill Reportnn";
cout<<"\t\t2.Add/Remove/Edit Itemnn";
cout<<"\t\t3.Show Item Detailsnn";
cout<<"\t\t4.Exitnn";
cout<<"\t\tPlease Enter Required Option: ";
int ch,ff;
float gtotal;
cin>>ch;
switch(ch)
{
case 1:
ss:
system("cls");
gotoxy(25,2);
cout<<"Bill Details";
gotoxy(25,3);
cout<<"================\n\n";
cout<<"\n\t\t1.All Itemsnn";
cout<<"\t\t2.Back to Main menu\n\n";
cout<<"\t\tPlease Enter Required Option: ";
int cho;
cin>>cho;
if(cho==1)
{
system("cls");
gotoxy(30,3);
cout<<" BILL DETAILS ";
gotoxy(3,5);
cout<<"ITEM NO";
gotoxy(13,5);
cout<<"NAME";
gotoxy(23,5);
cout<<"PRICE";
gotoxy(33,5);
cout<<"QUANTITY";
gotoxy(44,5);
cout<<"TAX %";
gotoxy(52,5);
cout<<"DISCOUNT %";
gotoxy(64,5);
cout<<"NET AMOUNT";
fin.open("itemstore.dat",ios::binary);
if(!fin)
{
cout<<"\n\nFile Not Found...";
goto menu;
}
fin.seekg(0);
gtotal=0;
while(!fin.eof())
{
fin.read((char*)&amt,sizeof(amt));
if(!fin.eof())
{
amt.report();
gtotal+=amt.retnetamt();
ff=0;
}
if(ff!=0)
gtotal=0;
}
gotoxy(17,k);
cout<<"\n\n\n\t\t\tGrand Total="<<gtotal;
getch();
fin.close();
}
if(cho==2)
{
    goto menu;
}
goto ss;
case 2:
db:
system("cls");
gotoxy(25,2);
cout<<"Bill Editor";
gotoxy(25,3);
cout<<"=================\n\n";
cout<<"\n\t\t1.Add Item Details\n\n";
cout<<"\t\t2.Edit Item Details\n\n";
cout<<"\t\t3.Delete Item Details\n\n";
cout<<"\t\t4.Back to Main Menu ";
int apc;
cin>>apc;
switch(apc)
{
case 1:fout.open("itemstore.dat",ios::binary|ios::app);
amt.add();
cout<<"\n\t\tItem Added Successfully!";
getch();
goto db;

case 2:
int ino;
flag=0;
cout<<"\n\n\tEnter Item Number to be Edited :";
cin>>ino;
fin.open("itemstore.dat",ios::binary);
fout.open("itemstore.dat",ios::binary|ios::app);
if(!fin)
{
cout<<"\n\nFile Not Found...";
goto menu;
}
fin.seekg(0);
r=0;
while(!fin.eof())
{
    fin.read((char*)&amt,sizeof(amt));
if(!fin.eof())
{
    int x=amt.item::retno();
if(x==ino)
{
flag=1;
fout.seekp(r*sizeof(amt));
system("cls");
cout<<"\n\t\tCurrent Details are\n";
amt.show();
cout<<"\n\n\t\tEnter New Details\n";
amt.add();
cout<<"\n\t\tItem Details editted";
}
}r++;
}
if(flag==0)
{
cout<<"\n\t\tItem No does not exist...Please Retry!";
getch();
goto db;
}
fin.close();
getch();
goto db;

case 3:flag=0;
cout<<"\n\n\tEnter Item Number to be deleted :";
cin>>ino;
fin.open("itemstore.dat",ios::binary);
if(!fin)
{
cout<<"\n\nFile Not Found...";
goto menu;
}
//fstream tmp("temp.dat",ios::binary|ios::out);
fin.seekg(0);
while(fin.read((char*)&amt, sizeof(amt)))
{
int x=amt.item::retno();
if(x!=ino)
tmp.write((char*)&amt,sizeof(amt));
else
{
flag=1;
}
}
fin.close();
tmp.close();
fout.open("itemstore.dat",ios::trunc|ios::binary);
fout.seekp(0);
tmp.open("temp.dat",ios::binary|ios::in);
if(!tmp)
{
cout<<"Error in File";
goto db;
}
while(tmp.read((char*)&amt,sizeof(amt)))
fout.write((char*)&amt,sizeof(amt));
tmp.close();
fout.close();
if(flag==1)
cout<<"\n\t\tItem Succesfully Deleted";
else if (flag==0)
cout<<"\n\t\tItem does not Exist! Please Retry";
getch();
goto db;
case 4:
goto menu;
default: cout<<"\n\n\t\tWrong Choice!!! Retry";
getch();
goto db;
}
case 3:system("cls");
flag=0;
int ino;
cout<<"\n\n\t\tEnter Item Number :";
cin>>ino;
fin.open("itemstore.dat",ios::binary);
if(!fin)
{
cout<<"\n\nFile Not Found...\nProgram Terminated!";
goto menu;
}
fin.seekg(0);
while(fin.read((char*)&amt,sizeof(amt)))
{
int x=amt.item::retno();
if(x==ino)
{
amt.pay();
flag=1;
break;
}
}
if(flag==0)
cout<<"\n\t\tItem does not exist....Please Retry!";
getch();
fin.close();
goto menu;
case 4:
system("cls");
gotoxy(20,20);
cout<<"ARE YOU SURE, YOU WANT TO EXIT (Y/N)?";
char yn;
cin>>yn;
if((yn=='Y')||(yn=='y'))
{
gotoxy(12,20);
system("cls");
cout<<"************************** THANKS **************************************";
getch();
exit(0);
}
else if((yn=='N')||(yn=='n'))
goto menu;
else
{
goto menu;
}
default:
cout<<"\n\n\t\tWrong Choice....Please Retry!";
getch();
goto menu;
}
return 0;
}

Write C++ Program with base class convert declares two variables, val1 and val2, which hold the initial and converted values, respectively. It also defines the functions getinit( ) and getconv( ), which return the initial value and the converted value. These elements of convert are fixed and applicable to all derived classes that will inherit convert. However, the function that will actually perform the conversion, compute( ), is a pure virtual function that must be defined by the classes derived from convert. The specific nature of compute( ) will be determined by what type of conversion is taking place.

/*
Prof.Parchure S.V.
*/
#include <iostream>
using namespace std;
class convert
{
    protected:
double val1;
double val2;
public: convert(double i)
{
    val1 = i;
}
double getconv()
{
    return val2;
}
double getinit()
{
    return val1;
}
virtual void compute() = 0;
};

class l_to_g : public convert
{
public:
l_to_g(double i) : convert(i)
{
}
void compute()
{
    val2 = val1 / 3.7854;
}
};
// Fahrenheit to Celsius
class f_to_c : public convert
{
public:
f_to_c(double i) : convert(i)
{
}
void compute()
{
val2 = (val1-32) / 1.8;
}
};

int main()
{
convert *p;
l_to_g lgob(4);
f_to_c fcob(70);

 p = &lgob;
cout<< p->getinit() << " liters is ";
p->compute();
cout<< p->getconv()<< " gallons\n";
p = &fcob;
cout<< p->getinit() << " in Fahrenheit is ";
p->compute();
cout<< p->getconv()<< " Celsius\n";
return 0;
}

Thursday 25 August 2016

Create employee bio-data using following classes i) Personal record ii))Professional record iii) Academic record Assume appropriate data members and member function to accept required data & print bio-data. Create bio-data using multiple inheritance using C++.

#include<iostream>
using namespace std;
class personal
{
protected:
char name[50];
char address[50];
char birthdate[50];
char gender;
public:
void get_personal();
};
class professional
{
protected:
int noofyearsexp;
char orgname[50];
char projname[50];
char projdetails[50];
public:
void get_professional();
};

class academic
{
protected:
int year;
int marks;
int percentage;
char Class[50];
public:
void get_academic();
};
class biodata: public personal,public academic,public professional
{
public:void display();
};
void personal::get_personal()
{
cout<<"Enter name::";
cin>>name;
cout<<"Enter Address::";
cin>>address;
cout<<"Enter Birthdate(dd/mm/yyyy)::";
cin>>birthdate;
cout<<"Enter gender(M/F)::";
cin>>gender;
}
void professional::get_professional()
{
cout<<"Enter number of years of exp::";
cin>>noofyearsexp;
cout<<"Enter organization name::";
cin>>orgname;
cout<<"Enter project name::";
cin>>projname;
cout<<"Enter project Details::";
cin>>projdetails;
}
void academic::get_academic()
{
cout<<"Enter academic year::";
cin>>year;
cout<<"Enter total marks::";
cin>>marks;
cout<<"Enter percentage::";
cin>>percentage;
cout<<"Enter class::";
cin>>Class;
}
void biodata::display()
{

     cout<<"---------------------Employee Biodata--------------"<<endl;
cout<<"-----------------------------------------------------"<<endl;
cout<<"____________________Personal Details__________________________"<<endl;
cout<<"Name::"<<name<<endl;
cout<<"address::"<<address<<endl;
cout<<"birthdate::"<<birthdate<<endl;
cout<<"Gender::"<<gender<<endl;
cout<<"--------------------------------------------------"<<endl;
cout<<"________________Academic Details________________________"<<endl;
cout<<"Academic Year "<<"marks "<<"percentage "<<"class "<<endl;
cout<<year<<"\t\t0"<<marks<<"\t"<<percentage<<"\t"<<Class<<endl;
cout<<"-------------------------------------------------------"<<endl;
cout<<"_______________Professional Details____________________"<<endl;
cout<<"\nOrganization Name::"<<orgname;
cout<<"\nYears of Experince::"<<noofyearsexp;
cout<<"\nProject Done::"<<projname;
cout<<"\nProject Details::"<<projdetails;
}
int main()
{
biodata b;
b.get_personal();
b.get_academic();
b.get_professional();
b.display();
}