Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> C/c++ Simple Machine Problems
abusado
post Nov 5 2004, 07:39 PM
Post #1


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



here are some of the c/c++ machine problems . a very simple but helpful


/*
machine problem 1 usage of scanf
*/
#include<stdio.h>
#include<conio.h>

main()
{
char name[10], add[20], schl[30], course[20], tel[20], cp[20], nationality[20], bday[20], pbirth[20], licno[20], sssno[20], sex[5];
char fname[20], mname[20], foccu[20], moccu[20], mbday[20], fbday[20];
int age, fage, mage;

clrscr();


gotoxy(35,2); printf("Bio-Data");
//your information
gotoxy(10,4); printf("Name: ");
scanf("%s",&name);
gotoxy(10,5); printf("Age: ");
scanf("%d",&age);
gotoxy(28,5); printf("Birtday: ");
scanf("%s",&bday);
gotoxy(50,5); printf("Sex: ");
scanf("%s",&sex);
gotoxy(10,6); printf("Address: ");
scanf("%s",&schl);
gotoxy(10,7); printf("Telephone #: ");
scanf("%s",&tel);
gotoxy(34,7); printf("Celphone #: ");
scanf("%s",&cp);
gotoxy(10,8); printf("School: ");
scanf("%s",&schl);
gotoxy(50,8);printf("Course: ");
scanf("%s",&course);
gotoxy(10,9); printf("Driver's lic. #: ");
scanf("%s",&licno);
gotoxy(50,9);printf("SSS #: ");
scanf("%s",&sssno);
gotoxy(10,10); printf("Place of birth: ");
scanf("%s",&pbirth);
gotoxy(50,10); printf("Nationality: ");
scanf("%s",&nationality);
//mother's information
gotoxy(10,12); printf("Mother's name: ");
scanf("%s",&mname);
gotoxy(10,13); printf("Age: ");
scanf("%d",&mage);
gotoxy(34,13); printf("Birthday: ");
scanf("%s",&mbday);
gotoxy(10,14); printf("Occupation: ");
scanf("%s",&moccu);
//father's information
gotoxy(10,16); printf("Father's name: ");
scanf("%s",&mname);
gotoxy(10,17); printf("Age: ");
scanf("%d",&mage);
gotoxy(34,17); printf("Birthday: ");
scanf("%s",&mbday);
gotoxy(10,18); printf("Occupation: ");
scanf("%s",&moccu);



getch();
return 0;
}
Go to the top of the page
 
+Quote Post
abusado
post Nov 5 2004, 07:41 PM
Post #2


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



/*
Machine Problem 2 Grade Computation Based on the philippines
Very helpful for teachers


*/
#include<stdio.h>
#include<conio.h>

main()
{
float q1, q2, quiz, cs, exam, pgrade, mgrade, fgrade, tgrade;
clrscr();

//prelim grade
gotoxy(5,5); printf("Q1 100pts:");
scanf("%f",&q1);
gotoxy(5,7); printf("Q2 100pts:");
scanf("%f",&q2);
gotoxy(5,9); printf("CS 100pts:");
scanf("%f",&cs);
gotoxy(5,11); printf("Exam 100pts:");
scanf("%f",&exam);
quiz = (q1 + q2) / 200 ;
pgrade = (quiz * 30) + ((cs / 100) * 30) + ((exam / 100) * 40);
gotoxy(5,14); printf("Prelim grade: %.2f",pgrade);
//midterm grade
gotoxy(30,5); printf("Q1 100pts:");
scanf("%f",&q1);
gotoxy(30,7); printf("Q2 100pts:");
scanf("%f",&q2);
gotoxy(30,9); printf("CS 100pts:");
scanf("%f",&cs);
gotoxy(30,11); printf("Exam 100pts:");
scanf("%f",&exam);
quiz = (q1 + q2) / 200 ;
mgrade = (quiz * 30) + ((cs / 100) * 30) + ((exam / 100) * 40);
gotoxy(30,14); printf("Midterm grade: %.2f",mgrade);
//final grade
gotoxy(55,5); printf("Q1 100pts:");
scanf("%f",&q1);
gotoxy(55,7); printf("Q2 100pts:");
scanf("%f",&q2);
gotoxy(55,9); printf("CS 100pts:");
scanf("%f",&cs);
gotoxy(55,11); printf("Exam 100pts:");
scanf("%f",&exam);
quiz = (q1 + q2) / 200 ;
fgrade = (quiz * 30) + ((cs / 100) * 30) + ((exam / 100) * 40);
gotoxy(55,14); printf("Final grade: %.2f",fgrade);

tgrade = (pgrade * .30) + (mgrade * .30) + (fgrade * .40);
gotoxy(30,18); printf("Total Grade: %.2f", tgrade);

getch();
return 0;
}
Go to the top of the page
 
+Quote Post
abusado
post Nov 5 2004, 07:44 PM
Post #3


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



/*
Machine Problem 3
Simple payroll system
*/
#include<stdio.h>
#include<conio.h>
#include<ctype.h>

main()
{
char name[30], pos;
float rate, hwrk, gross, bonus, tax, sss, med, tded, net;

clrscr();

gotoxy(10,5); printf("Name: ");
scanf("%s",&name);
gotoxy(30,6); printf("<m> Manager <s> Supervisor <e> Employee");
gotoxy(40,5); printf("Position: ");
pos = getch();
pos = tolower(pos);

if(pos == 'm')
{ rate = 500; }
else if(pos == 's')
{ rate = 400; }
else if(pos == 'e')
{ rate = 300; }
else
{ gotoxy(20,11); printf("Invalid entry! Press any key to exit");
getch();
return 0;
}

gotoxy(10,9); printf("Rate: %.0f", rate);
gotoxy(10,11); printf("No. of hours worked: ");
scanf("%f",&hwrk);

gross = rate * hwrk;
gotoxy(10,13); printf("Gross: %.2f",gross);

if(gross >= 5000)
{ bonus = 750; }
else if(gross <= 4999 && gross >= 3000)
{ bonus = 500; }
else
{ bonus = 0.0; }

gotoxy(10,14); printf("-----------------");
gotoxy(10,15); printf("Bonus: %.2f",bonus);

gotoxy(35,15); printf("Deductions:");

if(gross >= 7000)
{ tax = gross * 0.15; }
else if(gross <= 6999 && gross >= 4000)
{ tax = gross * 0.10; }
else if(gross <= 3999 && gross >= 2000)
{ tax = gross * 0.05; }
else
{ tax = 00.00; }

med = 100;
sss = gross * 0.10;
tded = tax + sss + med;
net = (gross + bonus) - tded;

gotoxy(35,16); printf("Tax: %.2f", tax);
gotoxy(35,17); printf("SSS: %.2f", sss);
gotoxy(35,18); printf("Medicare: %.2f", med);
gotoxy(35,19); printf("Total Deduction: %.2f", tded);
gotoxy(10,21); printf("Net Income: %.2f", net);




getch();
return 0;
}
Go to the top of the page
 
+Quote Post
abusado
post Nov 5 2004, 07:45 PM
Post #4


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



/*
Machine Problem 4
Switch and cases
*/
#include<stdio.h>
#include<conio.h>

main()
{
float num1, num2, ans;
char kp;
clrscr();

gotoxy(10,4); printf("First Number: ");
scanf("%f",&num1);
gotoxy(10,5); printf("Second Number: ");
scanf("%f",&num2);

gotoxy(10,7); printf("<+> Addition");
gotoxy(10,8); printf("<-> Subtraction");
gotoxy(10,9); printf("<*> Multiplication");
gotoxy(10,10); printf("</> Division");
gotoxy(10,11); printf("Enter your Choice -> [ ]");
gotoxy(32,11); printf("");
kp = getche();

switch(kp)
{
case '+': ans = num1 + num2;
break;
case '-': ans = num1 - num2;
break;
case '*': ans = num1 * num2;
break;
case '/': ans = num1 / num2;
break;
default: gotoxy(10,13); printf("Unknown command!");
break;
}
gotoxy(10,14); printf("The answer is: %.2f",ans);

getch();
return 0;
}
Go to the top of the page
 
+Quote Post
abusado
post Nov 5 2004, 07:49 PM
Post #5


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



/*
Machine Problem 5
LOOPING

For LOOP
*/
#include<stdio.h>
#include<conio.h>

main()
{
int a, b, x, y;


clrscr();
//1st multiplication table using two "for" loops
for(a = 1,y = 6; a <= 10; a++,y++)
{
for(b = 1, x = 7; b <= 10; b++,x = x + 3)
{
gotoxy(x,y); printf("%d",a*cool.gif;
}
}

//2nd multiplication table using 1 "for" loop
a = 1;
b = 1;
x = 47;
y = 6;
for(;;)
{
gotoxy(x,y); printf("%d", a*cool.gif;

if(b == 10)
{
a++;
b = 1;
x = 47;
y = y + 1;
}
else
{
b++;
x = x + 3;
}

if(a > 10)
{ break; }
else {}

}


getch();
return 0;
}
Go to the top of the page
 
+Quote Post
abusado
post Nov 5 2004, 07:51 PM
Post #6


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



/*
Functions = user define Functions
*/



#include<stdio.h>
#include<conio.h>
#include<ctype.h>

void circle();
void triangle();
void rectangle();
void square();

main()
{
char kp;
clrscr();

gotoxy(25,1); printf("A menu for the computation of the");
gotoxy(33,2); printf("area of the ff");
gotoxy(35,5); printf("a) circle ");
gotoxy(35,7); printf("b) triangle");
gotoxy(35,9); printf("c) rectangle");
gotoxy(35,11); printf("d) square");
gotoxy(30,15); printf("Entetr your selection:");
kp = getche();
kp = tolower(kp);

switch(kp)
{
case 'a': circle();
break;
case 'b': triangle();
break;
case 'c': rectangle();
break;
case 'd': square();
break;
}

getch();
return 0;
}

void circle()
{ float rad, ac;
clrscr();

gotoxy(27,1); printf("Area of a circle: 2ãr");
gotoxy(20,5); printf("Enter the radius of the circle: ");
scanf("%f",&rad);
ac = 2 * 3.1416 * rad;
gotoxy(20,7); printf("The are of the circle is: %.3f",ac);
gotoxy(27,10); printf("press any key to exit");

}
void triangle()
{ float base, height, at;
clrscr();

gotoxy(27,1); printf("Area of a triangle: «bh");
gotoxy(20,5); printf("Enter the base of the triangle: ");
scanf("%f",&base);
gotoxy(20,6); printf("Enter the height of the triangle: ");
scanf("%f",&height);
at = .5 * base * height;
gotoxy(20,8); printf("The area of the triangle is: %.2f",at);
gotoxy(27,13); printf("press any key to exit");


}
void rectangle()
{ float length, width, ar;
clrscr();

gotoxy(27,1); printf("Area of a rectangle: length * width");
gotoxy(20,5); printf("Enter the length of the triangle: ");
scanf("%f",&length);
gotoxy(20,6); printf("Enter the width of the triangle: ");
scanf("%f",&width);
ar = length * width;
gotoxy(20,8); printf("The area of the triangle is: %.2f", ar);
gotoxy(27,13); printf("press any key to exit");

}
void square()
{ float s, as;
clrscr();
gotoxy(27,1); printf("Area of a square: s * s");
gotoxy(20,5); printf("Enter one side of the square: ");
scanf("%f",&s);
as = s * s;
gotoxy(20,7); printf("The area of the square is: %.2f", as);
gotoxy(27,11); printf("press any key to exit");
}
Go to the top of the page
 
+Quote Post
abusado
post Nov 5 2004, 07:55 PM
Post #7


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



/*
Another multiplication table
*/


#include<stdio.h>
#include<conio.h>

main()
{
int xx[10], yy[10], x, y, xa, ya, xb, yb, a, b, cnt;

for(cnt = 1; cnt <=10; cnt++)
{ xx[cnt] = cnt; }
for(cnt = 1; cnt <=10; cnt++)
{ yy[cnt] = cnt; }
clrscr();

gotoxy(30,1); puts("Multiplication Table");

for(;;)
{ gotoxy(10,3); puts(" ");
gotoxy(10,3); printf("X: ");
scanf("%d",&x);
if(x >= 1 && x <= 10)
{ break; }
else{}
}

for(;;)
{ gotoxy(10,4); puts(" ");
gotoxy(10,4); printf("Y: ");
scanf("%d",&y);
if(y >= 1 && y <= 10 )
{ break; }
else{}
}

for(xb = 1,a=16; xb <= x; xb++,a=a+4)
{ gotoxy(a,8); printf("%d",xx[xb]);}
for(yb = 1,b=9; yb <= y; yb++,b++)
{ gotoxy(16,cool.gif; printf("%d",yy[yb]);}

for(ya = 1,b=9; ya <= y; ya++,b++)
{ a = 20;
for(xa = 1; xa <= x; xa++, a = a + 4)
{ gotoxy(a,cool.gif; printf("%d",xa*ya);}
}

getch();
return 0;
}
Go to the top of the page
 
+Quote Post
abusado
post Nov 5 2004, 07:56 PM
Post #8


Junior System Administrator
*

Group: Members
Posts: 22
Joined: 5-November 04
From: Philippines
Member No.: 2,147



/*
single dimension and 2 dimensional array

*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>

main()
{ int cnt,y,a;
char *prod[10][10], np[10], kp;

*prod[0] = "tomatoes";
*prod[1] = "cabbage";
*prod[2] = "potatoes";
*prod[3] = "mangoes";
*prod[4] = "bananas";
*prod[5] = "mushrooms";
*prod[6] = "bananas";
*prod[7] = "papayas";
*prod[8] = "langka";
*prod[9] = "guavas";


for(;;)
{
clrscr();

gotoxy(17,1); printf("Do you want to (l)ist, ®ead, (w)rite or (q)uit:");
kp = getch();
kp = tolower(kp);

switch(kp)
{
case 'l':
clrscr();
for(cnt=0,y=5; cnt <= 9; cnt++,y++)
{ gotoxy(15,y);
printf("product #%d: %s",cnt,*prod[cnt]);
}
gotoxy(20,20); puts("Press any key to return to main menu");
getch();
break;

case 'r':
clrscr();
gotoxy(20,5); printf("Enter product code: ");
scanf("%d",&a);
gotoxy(20,7); printf("Product #: %d ",a);
gotoxy(20,8); printf("Product name: %s",*prod[a]);
gotoxy(20,15); puts("Press any key to return to main menu");
getch();
break;

case 'w':
clrscr();
gotoxy(20,5); printf("Enter product code: ");
scanf("%d",&a);
gotoxy(20,7); printf("Product #:%d Product name: %s",a,*prod[a]);
gotoxy(20,9); printf("Enter new product name: ");
scanf("%s",&np);
strcpy(*prod[a],np);
gotoxy(20,11); printf("Successfully changed to: %s", *prod[a]);
gotoxy(20,17); puts("Press any key to return to main menu");
getch();
break;

case 'q' : exit(0);

}
}


}
Go to the top of the page