Jul 24, 2008

C/c++ Simple Machine Problems

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming
Pages: 1, 2

free web hosting

C/c++ Simple Machine Problems

abusado
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;
}

 

 

 


Reply

abusado
/*
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;
}

 

 

 


Reply

abusado
/*
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;
}

Reply

abusado
/*
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;
}

Reply

abusado
/*
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;
}

Reply

abusado
/*
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");
}

Reply

abusado
/*
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;
}

Reply

abusado
/*
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);

}
}


}

Reply

abusado
/*

input numbers and it will sort it...

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


float swap(float *a, float *cool.gif;

main()
{ float num[12],temp,r_add,r_mul;
//counters
int trig,cnt,y,cnta,ct;

for(cnt=1; cnt <= 10; cnt++)
{
clrscr();
gotoxy(20,5); printf("Entry # %d: Enter a number:",cnt);
scanf("%f",&temp);

trig = 1;
while(trig)
{
if(cnt == 1)
{
num[cnt] = temp;
temp = 0;
trig = 0;
}

else if(cnt == 2)
{
if(num[cnt-1] > temp)
{
swap(&num[cnt-1],&temp);
num[cnt] = temp;
}
else
{ num[cnt] = temp; }

temp = 0;
trig = 0;
}

else
{
cnta = cnt - 1;
for(ct = 1; ct <= cnta; ct++)
{
if(num[ct] > temp)
{
swap(&num[ct],&temp);
}
else{}
}
num[cnt] = temp;
temp = 0;
trig = 0;
}

}
}
clrscr();

gotoxy(15,5); puts("ASCENDING ORDER");
for(cnt=1,y=8; cnt <= 10; cnt++,y++)
{
gotoxy(20,y); printf("%.2f",num[cnt]);
}

gotoxy(50,5); puts("DECENDING ORDER");
for(cnt=10,y=8; cnt >= 1; cnt--,y++)
{
gotoxy(55,y); printf("%.2f",num[cnt]);
}

r_add = 0.0;
for(cnt = 1; cnt <= 10; cnt++)
{ r_add = r_add + num[cnt];}
gotoxy(20,20); printf("The sum of the numbers is: %.2f",r_add);

r_mul = 1.00;
for(cnt = 1; cnt <= 10; cnt++)
{ r_mul = r_mul * num[cnt];}
gotoxy(20,22); printf("The sum of the numbers is: %.2f",r_mul);

getch();
return 0;

}

float swap(float *a, float *cool.gif
{ float temp;

temp = *a;
*a = *b;
*b = temp;
return(*a,*cool.gif;
}

Reply

abusado
/*

Payroll
*/



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


main()
{
struct ret
{
char name[30];
char add[30];
char stat;
float hw; //hours worked
float hl; //hours late
float loans;
float debts;
float ded; //dedduction
float td; //total deductions
float gp; //gross pay
float np; //net pay
float ret; //retirement pay
float sss;
float pagibig;
float med; //medicare
float rph; //rate per hour
float oph; //overtime per hour
float lph; //late per hour
float ot; //overtime in hours
float late; //amount of lates
float itw;
float msal; //basic pay
int age;
int serv;
};

struct ret emp;
{
clrscr();
gotoxy(5,3); printf("Name: ");
scanf("%s",&emp.name);


gotoxy(50,3); printf("Age: ");
scanf("%d",&emp.age);

gotoxy(5,4); printf("Address: ");
scanf("%s",&emp.add);

gotoxy(5,9); printf("No. of hours worked: ");
scanf("%f",&emp.hw);

gotoxy(5,10); printf("No. of hours late: ");
scanf("%f",&emp.hl);

gotoxy(5,11); printf("No. of overtime hours: ");
scanf("%f",&emp.ot);
gotoxy(5,12); printf("Ammount Loans: ");
scanf("%f",&emp.loans);

gotoxy(5,13); printf("Ammount of debts: ");
scanf("%f",&emp.debts);

gotoxy(5,14); printf("No. of years in service: ");
scanf("%d",&emp.serv);

for(;;)
{
gotoxy(5,15); printf(" ");
gotoxy(5,15); printf("Status (P)mermanent (T)emporary: ");
emp.stat = getche();
emp.stat = tolower(emp.stat);

if(emp.stat == 'p' || emp.stat == 't')
{ break; }
else{}
}

emp.sss = 200.00;
emp.pagibig = 100.00;
emp.med = 100.00;

if(emp.stat == 'p')
{
emp.rph = 50.00;
emp.oph = 200.00;
emp.lph = 30.00;

emp.msal = (emp.rph * emp.hw) + (emp.oph * emp.ot);
emp.late = emp.lph * emp.hl;
emp.itw = .10 * emp.msal;
emp.ded = emp.sss + emp.pagibig + emp.med + emp.itw + emp.late;
emp.td = emp.ded + emp.loans + emp.debts;
emp.np = emp.msal - emp.td;
emp.ret = ((emp.np * 12) * emp.serv) - emp.ded;

gotoxy(50,9); puts("Deductions:");
gotoxy(50,10); printf("ITW: %.2f", emp.itw);
gotoxy(50,11); printf("Loans: %.2f", emp.loans);
gotoxy(50,12); printf("Debts: %.2f", emp.debts);
gotoxy(50,13); printf("SSS: %.2f", emp.sss);
gotoxy(50,14); printf("Pag-ibig: %.2f", emp.pagibig);
gotoxy(50,15); printf("Medicare: %f", emp.med);

gotoxy(27,17); printf("Monthly salary: %.3f", emp.np);
if(emp.ret <= 00.00)
{
emp.ret = 00.00;
gotoxy(10,21); puts("Sorry, you cannot avail your retirement benefit at this moment");
}
gotoxy(27,18); printf("Retirement Benefit: %.3f", emp.ret);
}

else
{
emp.rph = 45.00;
emp.oph = 150.00;
emp.lph = 30.00;

emp.msal = (emp.rph * emp.hw) + (emp.oph * emp.ot);
emp.late = emp.lph * emp.hl;
emp.itw = .10 * emp.msal;
emp.ded = emp.sss + emp.pagibig + emp.med + emp.itw + emp.late;
emp.td = emp.ded + emp.loans + emp.debts;
emp.np = emp.msal - emp.td;
emp.ret = 00.00;

gotoxy(50,9); puts("Deductions:");
gotoxy(50,10); printf("ITW: %.2f", emp.itw);
gotoxy(50,11); printf("Loans: %.2f", emp.loans);
gotoxy(50,12); printf("Debts: %.2f", emp.debts);
gotoxy(50,13); printf("SSS: %.2f", emp.sss);
gotoxy(50,14); printf("Pag-ibig: %.2f", emp.pagibig);
gotoxy(50,15); printf("Medicare: %f", emp.med);

gotoxy(27,17); printf("Monthly salary: %.3f", emp.np);
gotoxy(27,18); printf("Retirement Benefit: %.3f", emp.ret);
gotoxy(18,21); puts("Sorry, you cannot avail your retirement benefit");
}




}
getch();
return 0;

}

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Recent Queries:-
  1. c or c simple problems - 6.70 hr back. (1)
  2. c or c problems - 6.72 hr back. (1)
  3. c gotoxy printf - 47.50 hr back. (1)
  4. simple machines problems - 48.39 hr back. (1)
  5. machine problems on c and c - 61.92 hr back. (1)
  6. programming machine problems - 82.00 hr back. (1)
  7. c machine problems - 41.01 hr back. (5)
  8. "how to add loan tables in c " - 113.44 hr back. (1)
  9. gotoxy in c - 136.53 hr back. (4)
  10. machine problem c - 147.73 hr back. (3)
  11. programming machine problem - 147.95 hr back. (1)
Similar Topics

Keywords : c, c, simple, machine, problems

  1. Problems Unregistering Windows
    (0)
  2. Borland C++ Builder Problems
    I have tried simple examples.... (6)
    I have tried "programs" like hello world but I get erro with getchar or if I use with namespace!
    I don0t know what to do, I can't do anything ! Should I use visual c++ or other c++ I
    get same problems with dev c++, please help I must know why is that /wink.gif' border='0'
    style='vertical-align:middle' alt='wink.gif' /> ....

    1. Looking for c, c, simple, machine, problems

Searching Video's for c, c, simple, machine, problems
advertisement



C/c++ Simple Machine Problems



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE