C++ Program to implement Constructor Overloading – Q13
Q13. Program to implement Constructor Overloading:
Implement the concept of Constructor Overloading with the help of not less than three different constructors within any class of your choice.
… from College notes (BCA/MCA assignments):
#include <iostream.h>
#include <conio.h>
#include <string.h>
class Cperson{
private:
char name[20];
public:
Cperson(){
cout<<"\n Constructor Called."<<endl;
strcpy(name, "Manoj");
}
Cperson(char *str){
strcpy(name, str);
}
Cperson(Cperson &per){
strcpy(name, per.name);
}
void Show_Name(){
cout<<name;
}
};
void main(){
clrscr();
Cperson Op1;
Cperson Op2("Pandey");
Cperson Op3(Op2);
cout<<"\n Op1: ";
Op1.Show_Name();
cout<<"\n Op2: ";
Op2.Show_Name();
cout<<"\n Op3: ";
Op3.Show_Name();
getch();
}
Output:
Constructor Called.
Op1: Manoj
Op2: Pandey
Op3: Pandey
Build ASP.net pages without coding with ASP.net Maker
Recently I came across this cool tool which I’m using to create a web application for my company. Thanks to my boss/manager for introducing this tool and getting the full version.
With no or very less experience in MS.net I’ve completed the first iteration out of 5 (and many more to come) in the project. I just had previous knowledge of basic HTML, Javascript & C#/Java/C++ OOP fundamentals. My profile is of a Database Programmer and Technical Consultant with expertise in CRM technology in Finance & Print/Publishing domain.
The members in our team are more inclined towards backend technology with no or limited exposure to the web tech. So initially we thought to staff some extra resources from other teams who could help us creating front end and middle tier for us. With the introduction of this tool our problem was solved as we could create the pages with our own ideas and with much more flexibility and agility.
ASPM (short for ASP.net Maker) allows us to connect to any database and create pages dynamically as per our DB. It also facilitates us to create add/edit/delete/search pages with lot of more features. You just have to select any language either C# or VB.net, it creates the same code for you.
The more you use the tool the more you get to know about the features.
Some of the key features of this tool are:
– Advanced Security with MD5 and case-sensitive password
– User registration system with CAPTCHA option
– Export to CSV/HTML/Excel/Word/XML
– File uploading to database or folder
– Master/Detail
– Custom View
– Report
– Customizable template
– Database re-synchronization
– AJAX functionality
– Email Notification on Add/Edit/Delete
… and many more.
The only prerequisite to use this tool is knowledge of any database programming language so that one can design the database schema, tables, views, triggers, etc. I’m using MS SQL Server 2005 & using C# as a language option to create pages.
With the help of this tool not only I’m creating a application to facilitate users but also I’m learning ASP.net & C# and how to create web apps in MS.net technology.
May be its a beginning for the paradigm shift.
More info on: http://www.hkvstore.com/aspnetmaker
C++ Program to implement Toll Tax Problem by using CLASS Access Specifiers and SWITCH CASE – Q12
Q12. Program to implement Toll Tax Problem by using CLASS Access Specifiers and SWITCH CASE:
Calculate the toll tax for cars passing by a toll bridge @ Rs 5 per car (use the concept static data members). Calculate and Print the following details:
– Total no of cars passed with paying the tax
– Total amount of tax paid
– Total no of cars passed without paying tax.
… from College notes (BCA/MCA assignments):
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class TollBridge{
private:
static int car_yes, car_no;
static int amt;
public:
static void GetCar();
static void PutCar();
};
int TollBridge::car_yes = 0;
int TollBridge::car_no = 0;
int TollBridge::amt = 0;
void TollBridge :: GetCar(){
char ch;
cout<<"\n Total Cars Passed: "<<car_yes+car_no;
cout<<"\n This Car:- ";
cout<<"\n Paid Tax (y/n) ?: ";
cin>>ch;
if(ch == 'y'){
car_yes++;
amt += 5;
}
else
car_no++;
}
void TollBridge :: PutCar(){
cout<<"\n Total Car Passed: "<<car_yes+car_no<<endl;
cout<<"\n\t Car Passed by giving Tax: "<<car_yes;
cout<<"\n\t\t Amount Recieved: "<<amt<<endl;
cout<<"\n Car Passed by not giving Tax: "<<car_no;
}
void main(){
int ch;
char choice;
while(1){
clrscr();
cout<<"\n TOLL TAX PLAZA";
cout<<"\n ~~~~~~~~~~~~~~";
cout<<"\n 1 -> Entry of CARS.";
cout<<"\n 2 -> Report of CARS.";
cout<<"\n 3 -> Exit.";
cout<<"\n Enter your choice: ";
cin>>ch;
switch(ch){
case 1:
while(1){
TollBridge::GetCar();
cout<<"\n Do you want to continue
(y/n) ?: ";
cin>>choice;
if(choice =='n') break;
}
break;
case 2:
TollBridge::PutCar();
getch();
break;
default:
exit(1);
} // end of switch.
} // end of while.
} // end of main.
Output:
TOLL TAX PLAZA
1 -> Entry of CARS.
2 -> Report of CARS.
3 -> Exit.
Enter your choice: 1
Total Cars Passed: 0
This Car:-
Paid Tax (y/n) ?: y
Do you want to continue (y/n) ?: y
Total Cars Passed: 1
This Car:-
Paid Tax (y/n) ?: y
Do you want to continue (y/n) ?: y
Total Cars Passed: 2
This Car:-
Paid Tax (y/n) ?: y
Do you want to continue (y/n) ?: y
Total Cars Passed: 3
This Car:-
Paid Tax (y/n) ?: n
Do you want to continue (y/n) ?: y
Total Cars Passed: 4
This Car:-
Paid Tax (y/n) ?: n
Do you want to continue (y/n) ?: y
Do you want to continue (y/n) ?: n
TOLL TAX PLAZA
1 -> Entry of CARS.
2 -> Report of CARS.
3 -> Exit.
Enter your choice: 2
Total Car Passed: 5
Car Passed by giving Tax: 3
Amount Recieved: 15
Car Passed by not giving Tax: 2
C++ Program for CLASS Array Addition & Swapping by using Friend function – Q11
Q11. Program for CLASS Array Addition & Swapping by using Friend function:
Use the concept of Friend function for swapping the private array data members of two classes and getting the sum of two arrays within third class array member.
… from College notes (BCA/MCA assignments):
#include <iostream.h>
#include <conio.h>
class B;
class A{
private:
int arr[10];
int sum;
public:
void getdata();
friend void Swap(A &, B &);
friend void Sum(A *, B *);
void display() const;
};
class B{
private:
int arr[10];
int sum;
public:
void getdata();
friend void Swap(A &, B &);
friend void Sum(A *, B *);
void display() const;
};
void A :: getdata(){
cout<<"\n Enter 10 Numbers in Array A:- \n";
for(int i=0; i<10; i++)
cin>>arr[i];
}
void B :: getdata(){
cout<<"\n Enter 10 Numbers in Array B:- \n";
for(int i=0; i<10; i++)
cin>>arr[i];
}
void Swap(A &ob1, B &ob2){
int temp;
for(int i=0; i<10; i++){
temp = ob1.arr[i];
ob1.arr[i] = ob2.arr[i];
ob2.arr[i] = temp;
}
}
void Sum(A *ob1, B *ob2){
int sum = 0;
for(int i=0; i<10; i++)
sum += ob1->arr[i];
ob1->sum = sum;
cout<<"\n Sum of Array A : "<<sum;
sum = 0;
for(i=0; i<10; i++)
sum += ob2->arr[i];
ob2->sum = sum;
cout<<"\n Sum of Array B : "<<sum;
}
void A :: display() const{
cout<<"\n Elements of Array A are: ";
for(int i=0; i<10; i++)
cout<<" "<<arr[i];
}
void B :: display() const{
cout<<"\n Elements of Array B are: ";
for(int i=0; i<10; i++)
cout<<" "<<arr[i];
}
void main(){
A obj1;
B obj2;
clrscr();
cout<<"\n Friend Function programme:-"<<endl;
obj1.getdata();
obj2.getdata();
cout<<"\n Data Before Swapping:-"<<endl;
obj1.display();
obj2.display();
cout<<"\n Data After Swapping:-"<<endl;
Swap(obj1, obj2);
obj1.display();
obj2.display();
cout<<"\n Addition of Both Class's Arrays:-"<<endl;
Sum(&obj1, &obj2);
getch();
}
Output:
Friend Function program:-
Enter 10 Numbers in Array A:-
22 33 4 2 56 64 78 45 3 90
Enter 10 Numbers in Array B:-
67 543 5 67 89 90 12 0 12 70
Data Before Swapping:-
Elements of Array A are: 22 33 4 2 56 64 78 45 3 90
Elements of Array B are: 67 543 5 67 89 90 12 0 12 70
Data After Swapping:-
Elements of Array A are: 67 543 5 67 89 90 12 0 12 70
Elements of Array B are: 22 33 4 2 56 64 78 45 3 90
Addition of Both Class’s Arrays:-
Sum of Array A : 955
Sum of Array B : 397
C++ Program to work with Purchase Order Problem by using Pointers and CLASS with PUBLIC & PRIVATE Access Specifiers – Q10
Q10. Program to work with Purchase Order Problem:
Solve the following purchase order problem:
– Item list entry
– Bill generation
– Modify Item quantity purchased
– Remove Item from the list
… from College notes (BCA/MCA assignments):
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
class CBills{
private:
char name[20];
int qty;
float price, net;
public:
void Getinfo();
void Modify(CBills *, int );
void Remove(CBills *, int &);
void Display() const;
};
void CBills :: Getinfo(){
cout<<"\n Enter Item Name: ";
cin>>name;
cout<<"\n Enter Item Price: ";
cin>>price;
cout<<"\n Enter Item Quantity: ";
cin>>qty;
net = price * qty;
}
void CBills :: Modify(CBills *order, int no){
char key[15];
cout<<"\n Enter the Item Name to Modify: ";
cin>>key;
for(int i=0; i<=no; i++){
if(strcmp(order[i].name, key) == 0)
break;
}
cout<<"\n Enter Item Name: ";
cin>>order[i].name;
cout<<"\n Enter Item Price: ";
cin>>order[i].price;
cout<<"\n Enter Item Quantity: ";
cin>>order[i].qty;
order[i].net = order[i].price * order[i].qty;
}
void CBills :: Remove(CBills *order, int &no){
char key[15];
cout<<"\n Enter the Item Name to Remove: ";
cin>>key;
for(int i=0; i<=no; i++){
if(strcmp(order[i].name, key) == 0)
break;
}
for(int j=i; j<=no; j++)
order[j] = order[j+1];
no--;
}
void CBills :: Display() const{
cout<<"\n\t Item Name: "<<name;
cout<<"\n\t Item Price: "<<price;
cout<<"\n\t Item Quantity: "<<qty;
cout<<"\n\t Net Price: "<<net;
}
void main(){
CBills bills[20], bl;
int ch1, item_no = -1;
char ch2;
while(1){
clrscr();
cout<<"\n Inventory and Purchase Order Managament.";
cout<<"\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n 1 -> Get Item Details.";
cout<<"\n 2 -> Display Items.";
cout<<"\n 3 -> Modify an Item.";
cout<<"\n 4 -> Remove an Item.";
cout<<"\n 5 -> Exit.";
cout<<"\n Enter your choice: ";
cin>>ch1;
switch(ch1){
case 1: // Getinfo.
while(1){
clrscr();
item_no++;
cout<<"\n Entry of Purchased Items.";
cout<<"\n ~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n Item No. "<<item_no+1;
bills[item_no].Getinfo();
cout<<"\n Do you want to add more
(y/n): ";
cin>>ch2;
if(ch2 == 'n')
break;
}
break;
case 2: // Display.
clrscr();
cout<<"\n Purchase Order Details.";
cout<<"\n ~~~~~~~~~~~~~~~~~~~~~~~"; for(int i=0; i<=item_no; i++){
cout<<"\n\n Item No.: "<<i+1;
bills[i].Display();
}
break;
case 3: // Modify.
bl.Modify(bills, item_no);
cout<<"\n\n Record Modified.";
break;
case 4: // Remove.
bl.Remove(bills, item_no);
cout<<"\n\n Record Removed.";
break;
default:
exit(1);
} // end of switch.
getch();
} // end of while.
} // end of main.
Output:
Inventory and Purchase Order Managament.
1 -> Get Item Details.
2 -> Display Items.
3 -> Modify an Item.
4 -> Remove an Item.
5 -> Exit.
Enter your choice: 1
Entry of Purchased Items.
Item No. 1
Enter Item Name: Magazine
Enter Item Price: 100
Enter Item Quantity: 5
Do you want to add more (y/n): y
Entry of Purchased Items.
Item No. 2
Enter Item Name: Register
Enter Item Price: 50
Enter Item Quantity: 10
Do you want to add more (y/n): y
Entry of Purchased Items.
Item No. 3
Enter Item Name: Pen
Enter Item Price: 10
Enter Item Quantity: 20
Do you want to add more (y/n): n
Purchase Order Details.
Item No. Name Price Qty Net Price
1 Magazine 100 5 500
2 Register 50 10 500
3 Pen 10 20 200




