Sunday, March 29, 2009

Case2



#include
#include
#include
#include

int i=-1;
void add(),assort(),dessort(),view();

struct rec {
int id;
char Lastname [30];
char Firstname [30];
char position[30];
int age;
} ;
struct rec record[100];

main()
{
char choice;
clrscr();

printf("A] Add Employee Record\n");
printf("B] View Records\n");
printf("C] Exit\n");
printf("Choice: ");
scanf("%s",&choice);
choice=toupper(choice);
//choice=tolower(choice);
switch(choice)
{
case 'A':
i++;
add();
main();
case 'B':
view();
main();
case 'C':
printf("Thank You for Using");
getch();
exit(0);
default:
printf("Only letter a,b,and c");
getch();
main();
}

}
void add()
{
clrscr();
printf("Enter Account #: ");
scanf("%d",&record[i].id);
printf("Your Last name: ");
scanf("%d",&record[i].Lastname);gets(record[i].Lastname);
printf("Enter First name: ");
scanf("%d",&record[i].Firstname);gets(record[i].Firstname);
printf("Enter Position: ");
scanf("%d",&record[i].position);gets(record[i].position);
printf("Enter your Age: ");
scanf("%d",&record[i].age);

}
// --------------------------------Ascending Sort------------------------------
void assort()
{
struct rec T;
for(int x=i-1;x>=0;x--)
{
for(int y=0;y<=x;y++) { if(record[y].id>record[y+1].id)
{

T=record[y];
record[y]=record[y+1];
record[y+1]=T;
}
}
}
}
//--------------------------------Descending Sort---------------
void dessort()
{
struct rec T;
for(int x=i-1;x>=0;x--)
{
for(int y=0;y<=x;y++) { if(record[y].id
{

T=record[y];
record[y]=record[y+1];
record[y+1]=T;
}
}
}
}

//---------------------------------View-----------------------
void view()
{
int tt;
char h;
clrscr();
printf("Account #: Name: Position: Age:\n");
for( tt=0;tt<=i;tt++) { printf("%d %7s, %s %8s %9d\n",record[tt].id,record[tt].Lastname,record[tt].Firstname,record[tt].position,record[tt].age); } gotoxy(10,20);printf("press [A] - Ascending Sort"); gotoxy(10,21);printf("press [B] - Descending Sort"); gotoxy(10,22);printf("press [C] - Main Menu"); gotoxy(10,23);printf("choice: "); scanf("%s",&h); h=toupper(h); clrscr(); printf("Account #: Name: Position: Age:\n"); switch(h) { case 'A': assort(); for(tt=0;tt<=i;tt++) { printf("%d %7s, %s %8s %9d\n",record[tt].id,record[tt].Lastname,record[tt].Firstname,record[tt].position,record[tt].age); } break; case 'B': dessort(); for(tt=0;tt<=i;tt++) { printf("%d %7s, %s %8s %9d\n",record[tt].id,record[tt].Lastname,record[tt].Firstname,record[tt].position,record[tt].age); } break; case 'C': main(); break; default: clrscr(); printf("Only a and b"); getch(); break; } getch(); main(); }

Case1




#include
#include
#include
#include
#include
#include

int car;
int park[5]={0,0,0,0,0};

void view();
void out();
void in();
void loop();
void load();
void exit();
void swtch();
void frame();
void main()
{

clrscr();
frame();
load();
swtch();
getche();
}

void swtch(){
clrscr();
frame();
_setcursortype(_NOCURSOR);
char c[]={" G A R A G E P A R K I N G S Y S T E M "};
for(int i=0;i5)
{
gotoxy(27,15);textcolor(MAGENTA);cprintf("Slot does not exist!");
getch();

}

if(park[slot-1]==0)
{
park[slot-1]=plate;
gotoxy(25,15);textcolor(MAGENTA);cprintf("Slot was successfully occupied..");
getch();
}

else
{
gotoxy(27,15);textcolor(RED+BLINK);cprintf("Slot is already occupied!");
getch();
}
}

void out()
{
int slot,plate,hours;
int f,e;

gotoxy(34,6);textcolor(LIGHTBLUE);cprintf("O U T");
gotoxy(30,9);textcolor(YELLOW);cprintf("Enter slot:");
scanf("%d",&slot);
gotoxy(30,11);textcolor(YELLOW);cprintf("Enter Plate #: ");
scanf("%d",&plate);
gotoxy(30,13);textcolor(YELLOW);cprintf("Enter hours:");
scanf("%d",&hours);
gotoxy(26,21);textcolor(RED+BLINK);cprintf("Press any key to return...");

if(hours==1){
gotoxy(25,15);textcolor(YELLOW);cprintf(" Your total payment is P5.00");
scanf("%d", &f);
}
else if(hours>=1){
f=hours+2;

gotoxy(25,15);textcolor(YELLOW);cprintf("Your total payment is: P%d",f);
}
else{
gotoxy(29,16);textcolor(WHITE+BLINK);cprintf("INVALID HOURS!");
}
if(slot>5)
{
gotoxy(28,17);textcolor(RED+BLINK);cprintf("Error! Slot not found!!");
getch();
}
if(park[slot-1]==plate&&park[slot-1]!=hours)
{
park[slot-1]=0;
gotoxy(28,18);textcolor(WHITE);cprintf("Slot is now available.");
getch();
}
else
{
gotoxy(29,19);textcolor(WHITE+BLINK);cprintf("Invalid slot...");
getch();
}
}

void view()
{
int save;

gotoxy(28,6);textcolor(LIGHTBLUE);cprintf(" V I E W R E C O R D S");
gotoxy(26,9);textcolor(GREEN);cprintf(" SLOT PLATE # ");
gotoxy(26,21);textcolor(RED+BLINK);cprintf("Press any key to return...");

for(save=0;save<=4;save++) { gotoxy(28,10+save);textcolor(GREEN);cprintf("[%d] %d\n\n",save+1,park[save]); } getch(); } void frame() { int x,y; int a,b; for(x=1;x<=77;x++) { gotoxy(2+x,1);textcolor(7);cprintf("Ñ"); gotoxy(2+x,24);textcolor(7);cprintf("Ñ"); } for(y=1;y<=22;y++){ gotoxy(3,1+y);textcolor(YELLOW);cprintf("¶"); gotoxy(79,1+y);textcolor(YELLOW);cprintf("¶"); } gotoxy(3,1);textcolor(YELLOW);cprintf("É"); gotoxy(3,24);textcolor(YELLOW);cprintf("È"); gotoxy(79,1);textcolor(YELLOW);cprintf("»"); gotoxy(79,24);textcolor(YELLOW);cprintf("¼"); for(a=1;a<=49;a++) { gotoxy(15+a,4);textcolor(CYAN);cprintf("ß"); gotoxy(15+a,17);textcolor(CYAN);cprintf("Ü"); } for(b=1;b<=14;b++) { gotoxy(16,3+b);textcolor(CYAN);cprintf("Þ"); gotoxy(65,3+b);textcolor(CYAN);cprintf("Ý "); } time_t timer; struct tm *tblock; timer = time(NULL); tblock = localtime(&timer); gotoxy(35,23);textcolor(WHITE);cprintf("The time is: %s", asctime(tblock)); } void loop() { _setcursortype(_NOCURSOR); for(int e=0;e<=25;e++){ gotoxy(5+e,23);textcolor(YELLOW);cprintf("¯"); } for(int p=0;(p<=25*4);p++){ gotoxy(5+(p/4),23);textcolor(RED);cprintf("¯"); gotoxy(5,24);textcolor(6);cprintf("%d%",p); delay(7); } for(int o=0;o<=25;o++){ gotoxy(5+o,23);textcolor(GREEN);cprintf("¯"); } } void load() { _setcursortype(_NOCURSOR); for(int e=0;e<=25;e++){ gotoxy(5+e,23);textcolor(WHITE);cprintf("¯"); } gotoxy(9,20);textcolor(RED+BLINK);cprintf("LOADING......"); for(int i=0;(i<=50*2);i++){ gotoxy(5+(i/4),21);textcolor(RED);cprintf("¯"); gotoxy(5,22);textcolor(6);cprintf("%d%",i); delay(10); } for(int o=0;o<=25;o++){ gotoxy(5+o,23);textcolor(GREEN);cprintf("¯"); } } void exit() { clrscr(); frame(); _setcursortype(_SOLIDCURSOR); char c[]={"Thank You! and Come Again!!"}; for(int x=0;x
gotoxy(25+x,9);
textcolor(CYAN);
cprintf("%c",c[x]);
delay(40);
}}

exer7


#include
#include

void main(){
clrscr();
int day;
gotoxy(28,5);textcolor(LIGHTRED);cprintf("Enter an integer:");
scanf("%d",&day);

switch(day){
case 1:
gotoxy(30,10);textcolor(LIGHTGREEN+BLINK);cprintf("Sunday");
break;
case 2:
gotoxy(30,10);textcolor(LIGHTRED+BLINK);cprintf("Monday");
break;
case 3:
gotoxy(30,10);textcolor(MAGENTA+BLINK);cprintf("Tuesday");
break;
case 4:
gotoxy(30,10);textcolor(GREEN+BLINK);cprintf("Wednesday");
break;
case 5:
gotoxy(30,10);textcolor(CYAN+BLINK);cprintf("Thursday");
break;
case 6:
gotoxy(30,10);textcolor(YELLOW+BLINK);cprintf("Friday");
break;
case 7:
gotoxy(30,10);textcolor(LIGHTBLUE+BLINK);cprintf("Saturday");
break;

default:
gotoxy(20,10);textcolor(RED+BLINK);cprintf("S O R R Y ! ! !Day is not available!!!!!");}

gotoxy(25,13);textcolor(YELLOW+BLINK);cprintf("DONE BY: Diana Estrada");
getch();
}

exer8




#include
#include
#include

void menu();
void nextscreen();
void nextscreen2();
void nextscreen()
{

clrscr();
int x,y,z;for(x=1;x<=77;x++) { gotoxy(2+x,1);textcolor(LIGHTRED); cprintf("Í");//delay (10); gotoxy(2+x,21);textcolor(LIGHTRED); cprintf("Í");//delay (10); } for(y=1;y<=20;y++) { gotoxy(3,1+y);textcolor (LIGHTRED); cprintf("º");//delay (10);gotoxy(79,1+y);textcolor (LIGHTRED); cprintf("º");//delay (10);}gotoxy(3,1);textcolor (LIGHTRED); cprintf("É");gotoxy(3,21);textcolor (LIGHTRED); cprintf("È");gotoxy(79,1);textcolor (LIGHTRED); cprintf("»");gotoxy(79,21);textcolor (LIGHTRED); cprintf("¼"); } void menu(){nextscreen();nextscreen2 (); int choice,a,b,n,y,sum=0,sub=0,mul=0,div=0,z; gotoxy (26,6);textcolor(LIGHTRED); cprintf("\nSelect operation:"); gotoxy(25,8);textcolor(LIGHTGREEN); cprintf("\n\t[A] for ADDITION"); gotoxy (25,9);textcolor(LIGHTGREEN); cprintf("\n\t[B] for SUBTRACTION"); gotoxy(25,10);textcolor (LIGHTGREEN); cprintf("\n\t[C] for MULTIPLICATION"); gotoxy(25,11);textcolor(LIGHTGREEN); cprintf("\n\t[D] for DIVISION"); gotoxy (25,12);textcolor(LIGHTGREEN); cprintf("\n\t[E] for EXIT"); gotoxy(25,14);textcolor(LIGHTGREEN); cprintf("\nEnter choice here:");scanf("%s",&choice);switch(choice) {case 'A': clrscr(); nextscreen();nextscreen2(); gotoxy(35,5);textcolor(RED); cprintf ("A] A D D I T I O N"); gotoxy(25,7);textcolor(LIGHTRED); cprintf ("Enter number:");scanf("%d",&a); gotoxy(25,8); textcolor (LIGHTRED); cprintf("Enter another number:"); scanf("% d",&b); sum=a+b; gotoxy(25,10);textcolor (LIGHTGREEN+BLINK); cprintf("Sum of two number is: % d",sum); gotoxy(25,14);textcolor(LIGHTBLUE); cprintf("Do you want to try again,y/n?"); scanf("%s",&z);menu();getch();break; } switch(choice) {case 'B': clrscr();nextscreen();nextscreen2 (); gotoxy(35,5);textcolor(YELLOW); cprintf("B] S U B T R A C T I O N"); gotoxy(25,7);textcolor(LIGHTRED); cprintf("Enter number:");scanf("%d",&a); gotoxy(25,8);textcolor (LIGHTRED); cprintf("Enter another number:");scanf("% d",&b);sub=a-b;gotoxy(25,10); textcolor(YELLOW+BLINK); cprintf ("DIFFERENCE of two number is: %d",sub); gotoxy (25,14);textcolor(LIGHTBLUE); cprintf("Do you want to try again,y/n?"); scanf("%s",&z);menu();getch();break; } switch(choice) {case 'C': clrscr();nextscreen();nextscreen2();gotoxy (35,5);textcolor(YELLOW); cprintf("C] M U L T I P L I C A T I O N"); gotoxy(25,7);textcolor(LIGHTRED); cprintf("Enter number:"); scanf("%d",&a); gotoxy(25,8);textcolor (LIGHTRED); cprintf("Enter another number:"); scanf("% d",&b);mul=a*b; gotoxy(25,10);textcolor(YELLOW+BLINK); cprintf ("PRODUCT of two number is: %d",mul); gotoxy(25,14);textcolor(GREEN); cprintf("Do you want to try again,y/n?"); scanf("% s",&z);menu();getch();break; } switch(choice) { case 'D': clrscr();nextscreen();nextscreen2 (); gotoxy(35,5);textcolor(YELLOW); cprintf("D] D I V I S I O N"); gotoxy(25,7);textcolor(LIGHTRED); cprintf("Enter number:");scanf("%d",&a); gotoxy(25,8);textcolor (LIGHTRED); cprintf("Enter another number:"); scanf("% d",&b);div=a/b;gotoxy(25,10);textcolor(YELLOW+BLINK); cprintf ("QOUTIENT of two number is: %d",div); gotoxy(25,14);textcolor (LIGHTGREEN); cprintf("Do you want to try again,y/n?"); scanf("% s",&z);menu();getch();break; } switch(choice) { case'E': gotoxy(15,18);textcolor(LIGHTCYAN); cprintf("\n\nThe program ends here.. THANK YOU!"); } } void nextscreen2(){clrscr();int a,b,x,y,z;for(x=1;x<=77;x++){ gotoxy(2+x,1); textcolor(LIGHTCYAN); cprintf ("Í");gotoxy(2+x,21);textcolor(LIGHTCYAN); cprintf("Í");}for (y=1;y<=20;y++){ gotoxy(3,1+y);textcolor(LIGHTCYAN); cprintf ("º");gotoxy(79,1+y);textcolor(LIGHTCYAN); cprintf("º");}gotoxy (3,1);textcolor(LIGHTCYAN); cprintf("É");gotoxy(3,21);textcolor (LIGHTCYAN); cprintf("È");gotoxy(79,1);textcolor (LIGHTCYAN); cprintf("»");gotoxy(79,21);textcolor (LIGHTCYAN); cprintf("¼");for(a=1;a<=49;a++){ gotoxy (15+a,4);textcolor (LIGHTCYAN); cprintf("ß");gotoxy (15+a,17);textcolor(LIGHTCYAN); cprintf("Ü");}for (b=1;b<=14;b++){ gotoxy(16,3+b);textcolor(LIGHTCYAN); cprintf ("°");gotoxy(65,3+b);textcolor(LIGHTCYAN); cprintf("° ");} } void main(){clrscr();nextscreen();nextscreen2();menu(); getch(); }

Thursday, February 12, 2009

Exercise6


#include
#include


int num1,num2,ans;
int operation;
void main(){
clrscr();
gotoxy(20,5);
printf("W\tE\tL\tC\tO\tM\tE");
gotoxy(30,7);textcolor(WHITE);cprintf("Enter Number 1:");
scanf("%d",&num1);
gotoxy(30,8);textcolor(WHITE);cprintf("Enter Number 2:");
scanf("%d",&num2);
printf("\t\tA.) Addition \n");
printf("\t\tB.) Subtraction \n");
printf("\t\tC.) Multiplication \n");
printf("\t\tD.) Division \n");
printf(\n\t\t"Enter a Number above for the Operation: ",operation);
scanf("%sd",&operation);

switch(operation)
{
case 'A':
case 'a':

ans=num1+num2;
gotoxy(30,16);textcolor(WHITE);cprintf("The Answer is: %d",ans);
break;

case 'B':
case 'b':

ans=num1-num2;
gotoxy(30,16);textcolor(WHITE);cprintf("The Answer is: %d",ans);
break;

case 'C':
case 'c':

ans=num1*num2;
gotoxy(30,16);textcolor(WHITE);cprintf("The Answer is: %d",ans);
break;

case 'D':
case 'd':

ans=num1/num2;
gotoxy(30,16);textcolor(WHITE);cprintf("The Answer is: %d",ans);
break;

default:
gotoxy(30,15);textcolor(WHITE+BLINK);cprintf("Invalid Number!! Try Again!!");
}

getch();

}

Exercise4


#include
#include

void main()
{
int a, b, c;
int choice;

clrscr();
printf("\n Enter a number: ");
scanf("%d", &a);

printf("\n\t\t[A] - Pattern 1\n\n");
printf("\t\t[B] - Pattern 2\n\n");
printf("\t\t[C] - Pattern 3\n\n");
printf("\t\t[D] - Pattern 4\n\n");

printf("Select your choice: ");
scanf("%s",&choice);

switch (choice)
{
case 'A':
printf("\n ");
for(b=1; b<=a; b++) { for(c=1; c<=b; c++) printf("*"); printf("\n "); } break; case 'B': printf("\n "); for(c=a; c>=1; c--)
{
for(b=1; b<=c; b++) printf("*"); printf("\n "); } break; case 'C': printf("\n "); for(b=1; b<=a; b++) { for(c=1; c<=(a-b); c++) printf(" "); for(c=1; c<=b; c++) printf("*"); printf("\n "); } break; case 'D': printf("\n "); for(int b=a-1; b>=0; b--)
{
for(int c=b; c
printf(" ");
for(int d=0; d<=b; d++) printf("*"); printf("\n "); } break; default: clrscr(); printf("\n\n\n\n\t\t\tYour choice is not available!\n\n\n\n\t\t\tTry again later...!!!"); } getch(); }

Exercise3


#include
#include
int salary, years, bonus;
void main()
{
clrscr();
printf("Enter Salary:");
scanf("%d", &salary);
printf("Enter Years of Service:");
scanf("%d", &years);
bonus=0;
if (years==1){
bonus=salary*0.10;
printf("Bonus: %d", bonus);
}
else if ((years<=5) && (years>=2)){
bonus=salary*0.20;
printf("Bonus: %d", bonus);
}
else if ((years<=10) && (years>=6)){
bonus=salary*0.50 ;
printf("Bonus: %d", bonus);
}
else if (years<=11){ bonus=salary*0.75; printf("Bonus: %d", bonus); } getch(); }