Sunday, June 24, 2012
CS201Assignment No. 04 Semester: Spring 2012 CS201: Introduction to Programming
#include <iostream.h>
class location
{
public:
location();
location(int j,int i);
void display();
void* operator new (size_t);
void operator delete(void*);
location operator ++();
location operator --();
private:
int longitude;
int latitude;
};
location::location()
{
longitude=0;
latitude=0;
}
location::location(int j,int i)
{
longitude=j;
latitude=i;
}
void location::display()
{
cout<<"\n Longitude : "<<longitude;
cout<<"\n Latitude : "<<latitude;
}
void* location::operator new(size_t size)
{
cout<<"\nOverloaded New operator Called"<<endl;
void *pointer=malloc(size);
return pointer;
}
void location::operator delete(void *p)
{
cout<<"\nOverloaded delete operator Called"<<endl;
free(p);
}
location location::operator ++()
{
longitude+=1;
latitude+=1;
}
location location::operator --()
{
--longitude;
--latitude;
}
main()
{
location *loc,l2;
loc=new location(10,20);
loc->display();
cout<<"\nAfter calling Overloaded ++ operator";
++*loc;
loc->display();
cout<<"\n";
l2=location(30,40);
l2.display();
--l2;
cout<<"\nAfter calling Overloaded -- operator";
l2.display();
delete loc;
system ("pause");
}
Thursday, June 21, 2012
cs604 GDB solution Operating System fall june 2012
“Suppose a computer lab contains two printers, three tape
drives, and four terabyte crystal ROM writers. Assume process 2 is currently
using a printer and two crystal ROM writers, process 1 is using a tape drive,
and process 3 is using two crystal ROM writers, a tape drive, and a printer.
Suppose
now that process 2 requires a tape drive, process 1 requires a printer, and
process 3 requires one more crystal ROM writer. Does there exist any safe
sequence or not? Give reason/justification to support your answer.”
If you will give invalid reason/justification then you
will get zero marks with no leniency. Give reason precisely
and briefly to support your comments. The more you will be precise and brief in
your comments the more you will get the marks.
Solution:
Yes there exists
safe state.
When all processes take their resources then only one
tape drive remained free. Process 2 require 1 tape drive so process 2 gets it.
After using it and P2 free all its resources and now P1 Get Printer Resource
which is freed by P2. Now Process 3 Used 2 ROM, 2 ROM are already freed by P2.
SO we can easily say this that system is in safe state, no deadlock.
Tuesday, June 12, 2012
Assignment No. 03 Semester: Spring 2012CS201: Introduction to Programming
#include <iostream.h>
#include <string.h>
#include <conio.h>
using namespace std;
class Customer
{
public:
Customer();
Customer(string, int, int);
void setName(string);
void setCID(int);
void setSpend(int);
string getName();
int getCID();
int getSpend();
private:
string name;
int id;
int spending;
friend void sum(Customer&);
};
//-----------------------------------------------------------------------
Customer::Customer()
{
name = "no name";
id=0;
spending=0;
}
Customer::Customer(string n, int id, int spend)
{
name = n;
this->id=id;
spending=spend;
}
void Customer::setName(string n)
{
name = n;
}
void Customer::setCID(int n)
{
id = n;
}
void Customer::setSpend(int n)
{
spending = n;
}
string Customer::getName()
{
return name;
}
int Customer::getCID()
{
return id;
}
int Customer::getSpend()
{
return spending;
}
//-----------------------------------------------------------------------
void sum(Customer &cus)
{
double tax=0,d=0,t=0;
if(cus.spending < 5000)
{
tax = cus.spending*.05;
d = cus.spending*.01;
}
else if(cus.spending > 5000 && cus.spending < 10000)
{
tax = cus.spending*.10;
d = cus.spending*.02;
}
else if(cus.spending > 10000)
{
tax = cus.spending*.15;
d = cus.spending*.03;
}
t = cus.spending+tax-d;
cout<<"Customer Name :\t\t"<<cus.name<<endl;
cout<<"ID : \t\t\t"<<cus.id<<endl;
cout<<"Spending :\t\t"<<cus.spending<<endl;
cout<<"Total Bill :\t\t"<<t<<endl<<endl<<endl;
}
main()
{
Customer *cus1 = new Customer();
Customer *cus2 = new Customer("Ali", 112, 8550);
Customer *cus3 = new Customer();
cout<<"Bill detail for customer 1"<<endl;
sum(*cus1);
cout<<"Bill detail for customer 2"<<endl;
sum(*cus2);
char n[30];
int i;
int s;
cout<<"Enter the name of customer 3 : ";
cin>>n;
cout<<"Enter the ID of the customer 3 : ";
cin>>i;
cout<<"Enter total spending of customer 3 : ";
cin>>s;
cus3->setName(n);
cus3->setCID(i);
cus3->setSpend(s);
cout<<"\nBill detail for customer 3"<<endl;
sum(*cus3);
getch();
}
Subscribe to:
Posts (Atom)