Thursday, December 29, 2011

cs304 3 object oriented programming

#include <iostream.h>
#include <conio.h>
#include <string.h>
using namespace std;
class view;
class User;
class Members;
class Administrator;
class MemberList;
class Card;
class CategoryCatology;

class User{
      private:                
            
             
              string id;
              string name;
              string Address;
             
      public:
             void setId();
             string getId(); 
             void setName();
             string getName();
             void setAddress();
             string getAddress();           
             void viewCard();
             void searchCard(string);
             void verifyUser();
};

           
class Administrator: public User{
      private:                 
             
             
              int AdminID;
              char *name;
              char *address;
              MemberList *passward;
              CategoryCatology *catID; 
     
      public:                
             
             void AddCard();
             void DeleteCard();
             void SendCard();
             void CustomizedCard();
             void verifyUser();
};
                   
class Members: public User{  
     
      private:                  
             char *MemberID;
              char *address;
              MemberList *memberName;
             
      public:                             
             void SendCard();
             void CustomizedCard();
             void verifyUser();
};


//==================defination of functions of user class====================
void User::setId()
{
     string i;
     cout<<"Please enter the Id:"<<endl;
     cin>>i;
     id=i;
}
void User::setName()
{
     string s;
     cout<<"Please enter the Name:"<<endl;
     cin>>s;
     name=s;
}
void User::setAddress()
{
     string s;
     cout<<"Please enter the Address:"<<endl;
     cin>>s;
     Address=s;
}
string User::getId()
{
     return id;
}
string User::getAddress()
{
       return Address;
}
string User::getName()
{
       return name;
}
void User::viewCard()
{
     cout<<"cards are displayed"<<endl;
}
void User::searchCard(string c)
{
     cout<<c<<" is searched:"<<endl;
}
void User::verifyUser()
{
     cout<<getName()<<"is a user. "<<endl;
}
//==================defination of functions of admin class====================
void Administrator::AddCard()
{
     string c;
     cout<<"Please enter the name of the Card: ";
     cin>>c;
     cout<<c<<" card is added."<<endl;
}
void Administrator::DeleteCard()
{
     string c;
     cout<<"Please enter the name of the Card: ";
     cin>>c;
     cout<<c<<" card is deleted."<<endl;
}
void Administrator::SendCard()
{
     string c;
     cout<<"Please enter the name of the Card: ";
     cin>>c;
     cout<<c<<" card is sended."<<endl;
}
void Administrator::CustomizedCard()
{
     string c;
     cout<<"Please enter the name of the Card: ";
     cin>>c;
     cout<<c<<" card is Customized."<<endl;
}
void Administrator::verifyUser()
{
     cout<<getName()<<"is an Administrator. "<<endl;
}

//==================defination of functions of Members class====================

void Members::SendCard()
{
     string c;
     cout<<"Please enter the name of the Card: ";
     cin>>c;
     cout<<c<<" card is sended."<<endl;
}
void Members::CustomizedCard()
{
     string c;
     cout<<"Please enter the name of the Card: ";
     cin>>c;
     cout<<c<<" card is Customized."<<endl;
}
void Members::verifyUser()
{
     cout<<getName()<<"is a Member. "<<endl;
}
//=============================================================================
class View
{
      private:
             
      public:
             User u;
             Administrator a;
              Members m;
             void userop()
             {
                  char c;
                  cout<<"yor are a USER"<<endl;
                  cout<<u.getName()<<endl;
                  cout<<u.getAddress()<<endl;
                  cout<<u.getId()<<endl;
                  while(true)
                  {
                  cout<<"Please select a operation:"<<endl;
                  cout<<"v    for   verifyuser";
                  cin>>c;
                  u.verifyUser();
                  }
             }
             void adminop()
             {}
             void memop()
             {}
             void login()
             {
                  char usr;
                  cout<<"Please enter the user name from the givin:"<<endl;
                  cout<<"u    for   user\na    for   Admin\nm    for   member"<<endl;
                  cin>>usr;
                  if(usr == 'u')
                  {
                         User u;
                         u.setName();
                         u.setId();
                         u.setAddress();
                         userop();
                  }
                  if(usr == 'a')
                  {
                        
                         a.setName();
                         a.setId();
                         a.setAddress();
                         adminop();
                  }
                  if(usr == 'm')
                  {
                       
                         m.setName();
                         m.setId();
                         m.setAddress();
                         memop();
                  }
                 
             }
};
            

main()
{
     View v;
     v.login();
     
}
     

Tuesday, December 27, 2011

CS401 3 Computer Architecture and Assembly assignment solution fall december 2011

Copy the following code in "NOTEPAD" and save as

filename.asm

submit the asm file in vulms.

Please makes changes before submitting.



 [org 0x0100]
jmp start
oldisr: dd 0
message1: db 'Hello'
message2: db 'World'
;===============================================
kbisr:
 push ax
 push es
 mov ax, 0xb800
 mov es, ax
 in al, 0x60
;=======================Hello===================
 cmp al, 0x23
 jne nextcmp


mov ah, 0x13
mov al, 0
mov bh, 0
mov bl, 7
mov dx, 0x0000
mov cx, 5
push cs
pop es
mov bp, message1
int 0x10
 
 jmp exit
;=======================World===================
nextcmp:
 cmp al, 0x11
 jne nextcmp1
mov ah, 0x13
mov al, 0
mov bh, 0
mov bl, 7
mov dx, 0x0000
mov cx, 5
push cs
pop es
mov bp, message2
int 0x10


 jmp exit


;====================clear screen===============
nextcmp1:
 cmp al, 0x2e
 jne nomatch


mov ax, 0xb800
mov es, ax
mov di, 0
nextchar:
mov word [es:di], 0x0720
add di, 2
cmp di, 4000
jne nextchar


 jmp exit


;===============================================


nomatch:
 pop es
 pop ax
 jmp far [cs:oldisr]
;===============================================
exit:
 mov al, 0x20
 out 0x20, al
 pop es
 pop ax
 iret
;===================main========================
start:
 xor ax, ax
 mov es, ax
 mov ax, [es:9*4]
 mov [oldisr], ax
 mov ax, [es:9*4+2]
 mov [oldisr+2], ax
 cli
 mov word [es:9*4], kbisr
 mov [es:9*4+2], cs
 sti


 mov dx, start
 add dx, 15
 mov cl, 4
 shr dx, cl
 mov ax, 0x3100
 int 0x21

CS501 3 Advanced Computer Architecture Assignment solution fall december 2011

Question No.1:
Let us consider an I/O bus that can transfer 6 bytes of data in one bus cycle. presume that a designer is considering to attach the following two components to this bus:

Hard drive with a transfer rate of 80 M bytes/sec
Video card with a transfer rate of 200 M bytes/sec

What will be the implications if both of these components need to work simultaneously?
(The maximum frequency of the bus is 30 MHz)


Solution:

 The maximum frequency of the bus is 30 MHz. This means that the maximum bandwidth of this bus is 30 x 6 = 180 Mbytes/sec. Now, the demand for bandwidth from these two components will be 80 + 200 =280 Mbytes/sec which is more than the 180 Mbytes/sec that the bus can provide.
Thus, if the designer uses these two components with this bus, one or both of these components will be operating at reduced bandwidth.

Question No.2:

If a bus requires 15 nsec for bus requests, 10 nsec for arbitration and the average time to complete an operation is 10 nsec after the access to the bus has been granted, is it possible for such a bus to perform 40 million IOPS?

Solution:





For 40 million IOPS, the average time for each IOP is 1 / (40 x 106) =25 nsec. Given the
information about the bus, the sum of the three times is 10 + 10 + 15 = 35 nsec for a
complete I/O operation. This means that the bus can perform a maximum of 1 / ( 35 x 10-9 ) = 28.6 million IOPS.
Thus, it will not be able to perform 40 million IOPS.

Monday, December 26, 2011

CS402 theory of automata quizes

1. Two languages are said to belong to same class if they C when they run over an FA, that state  (May befinal State or not).
2. One language can have ……… CFG(s) 
(At least one)
3. If an FA has N state then it must accept the word of length 
(n+1)
4. In pumping lemma theorem (x y^n z) the range of n is 
(1,2,3,4,………)
5. For a non regular language there exist …… FA 
(NO)
6. If the intersection of two regular languages is regular then the complement of the intersection of these twolanguages is also regular 
(True)
7. According to Myhill Nerode theorem, if L generates finite no. of classes then L is
.......(Regular)
8. The language generated by the CFG is called the language ……by the CFG 
(Produced) 
9. If L1 and L2 are regular languages then which statement is NOT true? 
(L1/L2 is always regular)
10. The values of input (say a & b) does not remain same in one cycle due to 
(clock pulse)
11. The reverse of the string sbfsbb over { sb, f, b }
 (bsbfsb)
12. In CFG, the symbols that cannot be replaced by anything are called
 Terminals
13. a^n b^n generates the ………… language 
(Non regular languages)
14. The production S --> SS | a | b | ^ can be expressed by RE 
(a+b)+
Any word generated by given CFG can also be expressed by
 (Syntax tree or Generation
tree or Derivation tree as well)
15. Set of all palindromes over {a,b}is regular (false)
16. The grammatical rules which involves meaning of words are called
: (semantic)
17. An FA has same initial and final state, then it means that it has no final state. 
(false)
18. The same non terminals can be written in single line if they have more than one
..........(Productions)
19. In pref(Q in R) Q is …… to (than) R 
(Q is not equal to R)
20. The complement of a regular language is also a regular 
(True)
21. There is at least one production that has one........on its left side. 
(None Terminal)
22. For language L defined over {a, b},then L partitions {a, b}* into …… classes 
(Distinct) 

Sunday, December 25, 2011

cs602 3 Computer Graphics assignment solution fall december 2011

Question                                      20 marks
In the handouts of CS602 – Computer Graphics many examples are given in which GRAPHICS.H Header file is used. If you compile the given code in Dev-C++ IDE / Compiler the errors are reported because the given code is using GRAPHICS.H which is originally provided by Borland (www.borland.com). But there are ways to compile that code on Dev-C++. For this purpose you can consult the following tutorials:

  1. http://vulms.vu.edu.pk/Courses/CS602/Downloads/DevCppTutorialGraphics_h.pdf
  2. http://www.uniqueness-template.com/devcpp/

You are required to compile the given code after following the above tutorial and submit the following files in zip archive:
  1. Dev-C++ Project File (e.g. Project1.dev)
  2. C++ Source (e.g. main.cpp)
  3. O/Object File (mian.o)
  4. Makefile.win
  5. Executable File (e.g. Project1.exe) it is much necessary as a proof that you have successfully compiled the code.
  6. Microsoft Word File explaining the code.



Solution

asd
download the "graphics.h" and "libbgi.a" from the following link.

copy "graphics.h" into "C:\Dev-Cpp\include\"
and
"libbgi.a" into "C:\Dev-Cpp\lib\".

open devcpp and start new project. choose windows application from new project dialog.

create new source file and paste the below code into it.


Source Code:
#include <graphics.h>
#include <iostream>
#include <conio.h>
#include <math.h>
float round(float x){
      return x+0.5;
}
class Table{
private:
        int xc, yc;
        int xp, yp;
        int x1, x2, x3, x4;
        int y1, y2, y3, y4;
        int legLength;
        int sfx, sfy;
public:
Table(){
        xc=320, yc=240;
        xp=0; yp=0;
        x1=-10, x2=10, x3=10, x4=-10;
        y1=-7, y2=-7, y3=7, y4=7;
        legLength=10;
        sfx=1, sfy=1;
}
void translate(int tx, int ty){
        xp+=tx;
        yp+=ty;
}
void rotate (float angle){
        int tempx=x1;
        x1=tempx*cos(angle)-y1*sin(angle);
        y1=tempx*sin(angle)+y1*cos(angle);
        tempx=x2;
        x2=tempx*cos(angle)-y2*sin(angle);
        y2=tempx*sin(angle)+y2*cos(angle);
        tempx=x3;
        x3=tempx*cos(angle)-y3*sin(angle);
        y3=tempx*sin(angle)+y3*cos(angle);
        tempx=x4;
        x4=tempx*cos(angle)-y4*sin(angle);
        y4=tempx*sin(angle)+y4*cos(angle);
}
void scale(int sx, int sy){
        x1=x1*sx;
        x2=x2*sx;
        x3=x3*sx;
        x4=x4*sx;
        y1=y1*sy;
        y2=y2*sy;
        y3=y3*sy;
        y4=y4*sy;
        legLength=legLength*sy;
}
void draw(){
        int xc=this->xc+xp;
        int yc=this->yc+yp;
        line (xc+x1, yc+y1, xc+x2, yc+y2);
        line (xc+x2, yc+y2, xc+x3, yc+y3);
        line (xc+x3, yc+y3, xc+x4, yc+y4);
        line (xc+x4, yc+y4, xc+x1, yc+y1);
        line (xc+x1, yc+y1, xc+x1, yc+y1+legLength);
        line (xc+x2, yc+y2, xc+x2, yc+y2+legLength);
        line (xc+x3, yc+y3, xc+x3, yc+y3+legLength);
        line (xc+x4, yc+y4, xc+x4, yc+y4+legLength);
}};
int main(){
        //clrscr(); //it is not needed in DevCPP
        int gdriver = DETECT, gmode, errorcode;
        initgraph(&gdriver, &gmode, "c:\\Dev-Cpp\\lib");
        Table table;
        table.draw();
        setcolor(CYAN);
        table.translate(15, 25);
        table.draw();
        table.translate(50, 0);
        table.scale(3,2);
        table.draw();
        table.translate(-100, 0);
        table.rotate(3.14/4);
        table.draw();
        getch();
        closegraph();
return 0;
}


go to the menu "project -> project options" than "parameters" copy the below commands in the "linker field"

-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32

than compile the programe.

copy all the project files zip them and submit.
Thanks

Friday, December 23, 2011

cs201 3 Introduction to Programming Assignment Solution fall december 2011

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;
int random(int i)
{
    return rand()%i;
}
struct Reservation
{
       string Passenger_Name;
       string Passenger_Address;
       string Date_of_Flight;
       string Destination_to_travel;
       int Flight_No;
       int Seat_No;
};
void GetData(Reservation[],int);
void WriteData(Reservation[], int);
void ReadData(Reservation[], int); 
main()
{
      Reservation *res;
      int i;
      cout<<"How many reservation you want: ";
      cin>>i;
      res = new Reservation[i];
    
      GetData(res, i);
     
      system("pause");
     
}

void GetData(Reservation st[], int nn)
{
     string n;
     char ch;
     int l;
     for(int j=1;j<=nn;j++)
     {
             cout<<"Enter Passenger Name for Passenger "<<j<<" : ";
             cin>>n;
             st[j-1].Passenger_Name=n;
             cout<<"Enter Passenger Address for Passenger "<<j<<" : ";
             cin>>n;
             st[j-1].Passenger_Address=n; 
             cout<<"Enter Date of Flight for Passenger "<<j<<" : ";
             cin>>n;
             st[j-1].Date_of_Flight=n;
             cout<<"Enter Destination_to_travel for Passenger "<<j<<" : ";
             cout<<"Please Select from given"<<endl;
             cout<<"k       for         karachi"<<endl;
             cout<<"p       for         peshawar"<<endl;
             cout<<"L       for         lahore"<<endl;
             cin>>ch;
             if( ch == 'p')
             {
                 st[j-1].Destination_to_travel="Peshawar";
                 st[j-1].Flight_No=233; 
                 st[j-1].Seat_No=random(200);
             }
             if( ch == 'k')
             {
                 st[j-1].Destination_to_travel="Karachi";
                 st[j-1].Flight_No=201;
                 st[j-1].Seat_No=random(200); 
             }
             if( ch == 'l')
             {
                 st[j-1].Destination_to_travel="Lahore";
                 st[j-1].Flight_No=241; 
                 st[j-1].Seat_No=random(200);
             }
             else if( !(ch == 'p' || ch == 'k' || ch == 'l'))
             {
                       cout<<"Please select from list:"<<endl;
             }      
     }
     WriteData(st, nn);
}

void WriteData(Reservation abc[], int nn)
{
     ofstream myfile ("abc.txt");
      if (myfile.is_open())
      {
           for(int j=1;j<=nn;j++)
           {  
                myfile <<abc[j-1].Passenger_Name<<endl;
                myfile <<abc[j-1].Passenger_Address<<endl;
                myfile <<abc[j-1].Date_of_Flight<<endl;
                myfile <<abc[j-1].Destination_to_travel<<endl;
                myfile <<abc[j-1].Flight_No<<endl;
                myfile <<abc[j-1].Seat_No<<endl;
          
           }
           myfile.close();
      }
      else cout << "Unable to open file";
     ReadData(abc, nn);
}

void ReadData(Reservation[], int) 
{
       string line;
      ifstream myfile ("abc.txt");
      if (myfile.is_open())
      {
        while ( myfile.good() )
        {
          getline (myfile,line);
          cout << line << endl;
        }
        myfile.close();
      }
   
      else cout << "Unable to open file";
   
    
}