CGG PROGRAMS
======================================================
Assignment No.1
======================================================
Assignment No.1
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
class
computer
{
public :
void rect()
{
rectangle(320,10,630,460);
outtextxy(325,30,"Operation");
// line(350,40,400,40);
// line(395,30,400,40);
// line(395,50,400,40);
rectangle(510,20,580,45);
outtextxy(515,30,"Memory");
}
void q()
{
int a,b,c,d;
a=510;
b=110;
c=580;
rectangle(510,85,580,185);
for(int i=0;i<3;i++)
{
line(a,b,c,b);
b=b+25;
}
rectangle(510,210,580,260);
outtextxy(542,170,"1");
outtextxy(585,109,"Instru-");
outtextxy(585,121,"ction");
outtextxy(585,132,"Queue");
outtextxy(515,225,"Program");
outtextxy(515,245,"Counter");
}
void seg()
{
rectangle(360,110,430,235);
int a,b,c,d;
a=360;
b=135;
c=430;
for(int i=0;i<4;i++)
{
line(a,b,c,b);
b=b+25;
}
outtextxy(365,122,"ES=0000H");
outtextxy(365,147,"DS=0000H");
outtextxy(365,172,"CS=0000H");
outtextxy(365,197,"IP=0001H");
outtextxy(365,222,"DI=ALU");
}
void reg()
{
rectangle(360,280,430,455);
int a,b,c,d;
a=360;
b=305;
c=430;
for(int i=0;i<6;i++)
{
line(a,b,c,b);
b=b+25;
}
outtextxy(335,292,"AX");
outtextxy(335,317,"BX");
outtextxy(335,342,"CX");
outtextxy(335,367,"DX");
outtextxy(365,392,"SP=0001H");
outtextxy(365,417,"BP=0000H");
outtextxy(380,442,"FLAG");
}
void alu()
{
outtextxy(535,295,"ALU");
line(500,305,515,305);
line(515,305,530,330);
line(530,330,560,330);
line(560,330,575,305);
line(575,305,590,305);
line(515,355,500,305);
line(515,355,575,355);
line(575,355,590,305);
}
void flag()
{
rectangle(450,405,610,455);
int a,b,c;
a=470;
b=405;
c=455;
for(int i=0;i<7;i++)
{
line(a,b,a,c);
a=a+20;
}
line(450,430,610,430);
int x,y;
x=455;
y=417;
for(int j=0;j<4;j++)
{
outtextxy(x,y,"-");
x=x+20;
}
outtextxy(535,417,"O");
outtextxy(555,417,"D");
outtextxy(575,417,"I");
outtextxy(595,417,"T");
outtextxy(455,442,"S");
outtextxy(475,442,"Z");
outtextxy(495,442,"-");
outtextxy(515,442,"A");
outtextxy(535,442,"-");
outtextxy(555,442,"D");
outtextxy(575,442,"-");
outtextxy(595,442,"C");
}
void display(int a,int b,int c)
{
char n1[10],n2[10],n3[10],n4[10],n5[10],n6[6];
//int char
sprintf(n1,"%d",a);
sprintf(n2,"%d",b);
sprintf(n3,"%d",c);
//int to ascii
itoa(a,n4,2);
itoa(b,n5,2);
itoa(c,n6,2);
outtextxy(410,30,n2);
outtextxy(365,292,n1);
outtextxy(365,317,n2);
outtextxy(365,366,n6);
outtextxy(380,292,"=");
outtextxy(380,317,"=");
outtextxy(390,292,n4);
outtextxy(390,317,n5);
outtextxy(130,292,"Result is= ");
outtextxy(535,340,n6);
outtextxy(220,292,n3);
}
void arr()
{
outtextxy(430,30,"---->");
line(545,45,545,85);
line(540,80,545,85);
line(550,80,545,85);
line(585,330,600,330);
line(600,330,595,325) ;
line(600,330,595,335);
line(610,430,622,430);
line(622,430,617,425);
line(622,430,617,435);
line(545,185,545,210);
line(545,210,540,205);
line(545,210,550,205);
}
};
void main()
{
computer c;
int
gd=DETECT,gm,a,b,c1,ch;
clrscr();
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
cout<<"1.add\n";
cout<<"2.sub\n";
cout<<"3.mul\n";
cout<<"4.div\n";
cout<<"Enter 1st value\n";
cin>>a;
cout<<"Enter 2nd value\n";
cin>>b;
cout<<"Enter ur Choice\n";
cin>>ch;
switch(ch)
{
case 1:
c1=a+b;
break;
case 2:
c1=a-b;
break;
case 3:
c1=a*b;
break;
case 4:
c1=a/b;
break;
default:
cout<<"Invalid
choice" ;
break;
}
c.rect();
c.q();
c.seg();
c.reg();
c.alu();
c.flag();
c.arr();
c.display(a,b,c1);
getch();
}
…………………………………………………………………
Output