#include <iostream.h>
#include <fstream.h>
#include <string.h>
using namespace std;
string karachi="Karachi",lahore="Lahore",peshawar="Peshawar";
class Airfare
{
private:
char seatType;
int price;
float tax;
double airlinecharg;
double fare;
string destination, name, date, address, flightNo, seatNo;
public:
enum Type
{
economy,
business,
first
};
Type type;
void getData();
void readData();
void setDestination(string i){destination=i;};
double calculatePrice();
float CalculateTax();
void calFare();
void writeDatafile();
void writeDatascreen();
Airfare(){
seatType=' ';
price=tax=airlinecharg=fare=0.0;
destination=name=date=address=flightNo=seatNo="default";};
};
void Airfare::getData()
{
int i;
do
{
cout<<"Please select the Seat Type:"<<endl;
cout<<" 1 for Economy Class"<<endl;
cout<<" 2 for Business Class"<<endl;
cout<<" 3 for First Class"<<endl;
cin>>i;
}
while(i>3 || i<1);
type = Type(i);
}
void Airfare::readData()
{
string line;
ifstream myfile ("data.txt");
if (myfile.is_open())
{
getline (myfile,line);
name=line;
getline (myfile,line);
address=line;
getline (myfile,line);
date=line;
getline (myfile,line);
destination=line;
getline (myfile,line);
flightNo=line;
getline (myfile,line);
seatNo=line;
myfile.close();
}
else cout << "Unable to open file";
}
double Airfare::calculatePrice()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+3000)*0.15;
return tax+3000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+5000)*0.15;
return tax+5000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+4000)*0.15;
return tax+4000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+6000)*0.15;
return tax+6000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+2500)*0.15;
return tax+2500+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+4500)*0.15;
return tax+4500+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
}
float Airfare::CalculateTax()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
tax=4000*0.10;
break;
case 2://business class
tax=6000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
tax=3000*0.10;
break;
case 2://business class
tax=3000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
tax=2500*0.10;
break;
case 2://business class
tax=4500*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
fare=calculatePrice();
}
void Airfare::writeDatafile()
{
ofstream myfile ("fare.txt");
if (myfile.is_open())
{
myfile<<"_________________________________________________________________________"<<endl;
myfile<<"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"<<endl;
myfile<<"-------------------------------------------------------------------------"<<endl;
myfile<<"| "<<name<<" | "<<address<<" | "<<date<<" | "<<destination<<" | "<<flightNo<<" | "<<seatNo<<" | "<<fare<<" | "<<endl;
myfile<<endl;
myfile<<endl;
myfile<<endl;
myfile<<endl;
myfile<<endl;
myfile<<endl;
myfile<<endl;
myfile<<endl;
myfile<<"-------------------------------------------------------------------------"<<endl;
myfile.close();
}
else cout << "Unable to open file";
}
void Airfare::writeDatascreen()
{
cout<<"_________________________________________________________________________"<<endl;
cout<<"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"<<endl;
cout<<"-------------------------------------------------------------------------"<<endl;
cout<<"| "<<name<<" | "<<address<<" | "<<date<<" | "<<destination<<" | "<<flightNo<<" | "<<seatNo<<" | "<<fare<<" | "<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"-------------------------------------------------------------------------"<<endl;
}
void Airfare::calFare()
{
fare=calculatePrice();
}
main()
{
Airfare a;
a.getData();
a.readData();
a.CalculateTax();
a.calculatePrice();
a.calFare();
a.writeDatafile();
a.writeDatascreen();
system("pause");
}
Wednesday, January 25, 2012
Monday, January 23, 2012
CS401 5 Computer Architecture and Assembly Language Programming assignment solution fall 2012
Assignment No. 05
Semester: Fall 2011
Semester: Fall 2011
CS401: Computer Architecture and Assembly Language Programming
Question No. 1: 10 Marks
In Example 12.4 Line# 6, an instruction is given to define a greeting message as below:
6. message: db 10, 13, 'hello $' ; greetings message
- What is the purpose of including the values 10 and 13 as these values are not printed on output screen?
10 is used for new line. It is used to start a new line. 10 is the new line character in ASCII code.
13 is the carriage return.
So they are not shown in output.
- What is the purpose of writing $ at the end of the string message?
$ is a terminator character. We use the service no 09 of the DOS. This service takes the $ sign as the terminator of the string.
Question No. 2: 10 Marks
This question is based upon Elementary multitasking of two threads Example 11.1 given in Lectures handouts. Given code in example 11.1 creates two simple threads each rotating bars by changing characters at the two corners of the screen and have infinite loops. Its output looks like as below:
Line # | Instruction to be added/modified | New/Modified Instruction |
11 | chars: db '\|/-' | chars: db '01234567' |
17 | and bx, 3 | and bx, 7 |
24 | and bx, 3 | and bx, 7 |
Sunday, January 22, 2012
CS501 5 Advance Computer Architecture assignment solution fall 2012
Question No. 1
According to the Radix conversion algorithm, convert 49210 to base 16 (Write down all the steps which are involved in conversion).
Answer:
492/16 =30( rem=12), x0=12=C
30/16= 1(rem=14), x1=14=E, x2=1
Thus 49210=1EC16
Question No. 2
According to the Radix conversion algorithm, convert the hexadecimal number D416 to base 10 (Write down all the steps which are involved in conversion).
Answer:
X=0
X= x+D (=13) =13
X=16*13+4= 212
Hence D416=21210
Wednesday, January 18, 2012
cs402 5 Theory of Automata (CS402) Assignment Solution
Theory of Automata (CS402)
Assignment No.5
Deadline
Your assignment must be uploaded before or on.
Rules for Marking
It should be clear that your assignment will not get any credit if:
· The assignment is submitted after due date
· The assignment is copied
Objectives
Objective of this assignment is to make you able to understand the following concepts,
· Defining Context Free Grammars for Different Languages
· Null and Null-able Transitions and Regular Context Free Grammars
· Chomsky Normal Form
· Push Down Automata
Question No.1
Give CFG for the following languages,
- anbm where n = m-1 and n = 1,2,3…
Some words belonging to this language are, a , aab , aaabb , aaaabbb , ….
∑ = {a,b}
S Ã aX
X à aXb | ab | Λ
- anb2n where n = 1,2,3…
Some words belonging to this language are, abb , aabbbb , aaabbbbbb , ….
∑ = {a,b}
S Ã aSbb
S Ã abb
S à Λ
Question No.2
Consider the CFG given below and find Null and Null-able transitions (if any) also remove these transitions to give new CFG
S ---- > ABB | CC | ABC | AC
A --- > a | Є
B --- > b | C
C --- > ab | Є
[Here Є means null string, as in CFG’s we use Є for indicating null string instead of ^ sign]
Solution:
A Ã a
B Ã b | C
C Ã ab
Question No.3
Convert the CFG (Context Free Grammar) given below to CNF (Chomsky Normal Form)
S ---- > YYY | ZZ | aa | bb
Y --- > a | Z
Z --- > b | Y
Solution:
R Ã YY
Y Ã a | Z
Z Ã b | Y
Question No.4
Design PDA (Push Down Automata) for the language given below,
(ba)n(a)n n = 1,2,3…
Monday, January 16, 2012
cs201 4 Introduction to Programming assignment solution fall 2012
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;
int random(int i)
{
return rand()%i;
}
struct Time
{
int hour,mins;
};
class Schedule{
private:
bool Trip;
string Date_of_departure;
string Date_of_return;
string Destination;
string Origin;
int Flight_No;
Time Departure_time;
Time Arrival_time;
public:
Schedule();
~Schedule();
void ReadData();
void WriteData();
void GetData();
};
Schedule::Schedule()
{
Trip=0;
Date_of_departure = "Not Entered";
Date_of_return = "Not Entered";
Destination = "Not Entered";
Origin = "Not Entered";
Flight_No = 00;
Departure_time.hour = 00;
Departure_time.mins = 01;
Arrival_time.hour=00;
Arrival_time.mins=00;
}
Schedule::~Schedule()
{
}
main()
{
Schedule s;
s.GetData();
system("pause");
}
void Schedule::WriteData()
{
ofstream myfile ("schedule.txt");
if (myfile.is_open())
{
myfile <<"Flight No : "<<Flight_No<<endl;
myfile <<"Origin : "<<Origin<<endl;
myfile <<"Destination : "<<Destination<<endl;
myfile <<"Date of departure : "<<this->Date_of_departure<<endl;
myfile <<"Date of return : "<<this->Date_of_return<<endl;
myfile <<"Departure time : "<<this->Departure_time.hour<<" : "<<Departure_time.mins<<endl;
myfile <<"Arrival time : "<<this->Arrival_time.hour<<" : "<<Arrival_time.mins<<endl;
myfile.close();
}
else cout << "Unable to open file";
ReadData();
}
void Schedule::ReadData()
{
string line;
ifstream myfile ("schedule.txt");
cout<<"\n\n\n";
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
}
void Schedule::GetData()
{
string n;
char ch;
int l;
cout<<"Please enter \"t for true\" and \"f for falls\""<<" : ";
cin>>ch;
if(ch == 't')
{
Trip=true;
cout<<"Enter Date of departure "<<" : ";
cin>>Date_of_departure;
cout<<"Enter Date of return "<<" : ";
cin>>Date_of_return;
cout<<"Enter Destination_to_travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Destination="Peshawar";
Flight_No=random(200);
}
if( ch == 'k')
{
Destination="Karachi";
Flight_No=random(200);
}
if( ch == 'l')
{
Destination="Lahore";
Flight_No=random(200);
}
if( ch == 'i')
{
Destination="Islamabad";
Flight_No=random(200);
}
if( ch == 'q')
{
Destination="Quetta";
Flight_No=random(200);
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
cout<<"Enter Origin to travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Origin="Peshawar";
}
if( ch == 'k')
{
Origin="Karachi";
}
if( ch == 'l')
{
Origin="Lahore";
}
if( ch == 'i')
{
Origin="Islamabad";
}
if( ch == 'q')
{
Origin="Quetta";
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
Departure_time.hour=random(12);
Departure_time.mins=random(60);
if(Departure_time.hour+2 <=12)
{
Arrival_time.hour=Departure_time.hour+2;
Arrival_time.mins=Departure_time.mins;
}
else
{
Arrival_time.hour=(Departure_time.hour+2)%12;
Arrival_time.mins=Departure_time.mins;
}
}
else if(ch == 'f')
{
Trip=0;
cout<<"Enter Date of departure "<<" : ";
cin>>Date_of_departure;
cout<<"Enter Destination to travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Destination="Peshawar";
Flight_No=random(200);
}
if( ch == 'k')
{
Destination="Karachi";
Flight_No=random(200);
}
if( ch == 'l')
{
Destination="Lahore";
Flight_No=random(200);
}
if( ch == 'i')
{
Destination="Islamabad";
Flight_No=random(200);
}
if( ch == 'q')
{
Destination="Quetta";
Flight_No=random(200);
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
cout<<"Enter Origin_to_travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Origin="Peshawar";
}
if( ch == 'k')
{
Origin="Karachi";
}
if( ch == 'l')
{
Origin="Lahore";
}
if( ch == 'i')
{
Origin="Islamabad";
}
if( ch == 'q')
{
Origin="Quetta";
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
Departure_time.hour=random(12);
Departure_time.mins=random(60);
if(Departure_time.hour+2 <=12)
{
Arrival_time.hour=Departure_time.hour+2;
Arrival_time.mins=Departure_time.mins;
}
else
{
Arrival_time.hour=(Departure_time.hour+2)%12;
Arrival_time.mins=Departure_time.mins;
}
}
WriteData();
}
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;
int random(int i)
{
return rand()%i;
}
struct Time
{
int hour,mins;
};
class Schedule{
private:
bool Trip;
string Date_of_departure;
string Date_of_return;
string Destination;
string Origin;
int Flight_No;
Time Departure_time;
Time Arrival_time;
public:
Schedule();
~Schedule();
void ReadData();
void WriteData();
void GetData();
};
Schedule::Schedule()
{
Trip=0;
Date_of_departure = "Not Entered";
Date_of_return = "Not Entered";
Destination = "Not Entered";
Origin = "Not Entered";
Flight_No = 00;
Departure_time.hour = 00;
Departure_time.mins = 01;
Arrival_time.hour=00;
Arrival_time.mins=00;
}
Schedule::~Schedule()
{
}
main()
{
Schedule s;
s.GetData();
system("pause");
}
void Schedule::WriteData()
{
ofstream myfile ("schedule.txt");
if (myfile.is_open())
{
myfile <<"Flight No : "<<Flight_No<<endl;
myfile <<"Origin : "<<Origin<<endl;
myfile <<"Destination : "<<Destination<<endl;
myfile <<"Date of departure : "<<this->Date_of_departure<<endl;
myfile <<"Date of return : "<<this->Date_of_return<<endl;
myfile <<"Departure time : "<<this->Departure_time.hour<<" : "<<Departure_time.mins<<endl;
myfile <<"Arrival time : "<<this->Arrival_time.hour<<" : "<<Arrival_time.mins<<endl;
myfile.close();
}
else cout << "Unable to open file";
ReadData();
}
void Schedule::ReadData()
{
string line;
ifstream myfile ("schedule.txt");
cout<<"\n\n\n";
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
}
void Schedule::GetData()
{
string n;
char ch;
int l;
cout<<"Please enter \"t for true\" and \"f for falls\""<<" : ";
cin>>ch;
if(ch == 't')
{
Trip=true;
cout<<"Enter Date of departure "<<" : ";
cin>>Date_of_departure;
cout<<"Enter Date of return "<<" : ";
cin>>Date_of_return;
cout<<"Enter Destination_to_travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Destination="Peshawar";
Flight_No=random(200);
}
if( ch == 'k')
{
Destination="Karachi";
Flight_No=random(200);
}
if( ch == 'l')
{
Destination="Lahore";
Flight_No=random(200);
}
if( ch == 'i')
{
Destination="Islamabad";
Flight_No=random(200);
}
if( ch == 'q')
{
Destination="Quetta";
Flight_No=random(200);
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
cout<<"Enter Origin to travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Origin="Peshawar";
}
if( ch == 'k')
{
Origin="Karachi";
}
if( ch == 'l')
{
Origin="Lahore";
}
if( ch == 'i')
{
Origin="Islamabad";
}
if( ch == 'q')
{
Origin="Quetta";
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
Departure_time.hour=random(12);
Departure_time.mins=random(60);
if(Departure_time.hour+2 <=12)
{
Arrival_time.hour=Departure_time.hour+2;
Arrival_time.mins=Departure_time.mins;
}
else
{
Arrival_time.hour=(Departure_time.hour+2)%12;
Arrival_time.mins=Departure_time.mins;
}
}
else if(ch == 'f')
{
Trip=0;
cout<<"Enter Date of departure "<<" : ";
cin>>Date_of_departure;
cout<<"Enter Destination to travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Destination="Peshawar";
Flight_No=random(200);
}
if( ch == 'k')
{
Destination="Karachi";
Flight_No=random(200);
}
if( ch == 'l')
{
Destination="Lahore";
Flight_No=random(200);
}
if( ch == 'i')
{
Destination="Islamabad";
Flight_No=random(200);
}
if( ch == 'q')
{
Destination="Quetta";
Flight_No=random(200);
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
cout<<"Enter Origin_to_travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Origin="Peshawar";
}
if( ch == 'k')
{
Origin="Karachi";
}
if( ch == 'l')
{
Origin="Lahore";
}
if( ch == 'i')
{
Origin="Islamabad";
}
if( ch == 'q')
{
Origin="Quetta";
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
Departure_time.hour=random(12);
Departure_time.mins=random(60);
if(Departure_time.hour+2 <=12)
{
Arrival_time.hour=Departure_time.hour+2;
Arrival_time.mins=Departure_time.mins;
}
else
{
Arrival_time.hour=(Departure_time.hour+2)%12;
Arrival_time.mins=Departure_time.mins;
}
}
WriteData();
}
Subscribe to:
Comments (Atom)