C Professionals Only! Problem #1: (40 pts)<?xml:namespace prefix = o ns = \"urn:
ID: 3531334 • Letter: C
Question
C Professionals Only!
Problem #1: (40 pts)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Write an application that translates an alphabetic phone number into
a numeric number. If the phone number contains non-alphabetic characters
leave them unchanged. You are to continue to enter phone numbers until the user decides to exit the application.
Enter a phone number: out2SEA
Numeric number: 6882732
Enter a phone number: 1-800-OUT-2SEA
Numeric number: 1-800-688-2732
letters on the keys:
2 = ABC, 3 = DEF, 4 = GHI, 5 = JKL, 6 = MNO
7 = PRS, 8 = TUV, 9 = WXYZ
Pseudocode
read in characters as a string
convert lower case characters to upper case
use switch statement to convert alpha characters to numeric characters
store output numeric number in a character array -- char phoneNumber[MAXNUMBER]
then print out the phoneNumber array
Problem #2: (40 pts)
Write an application that reads in students
Explanation / Answer
//You have too many question in one post, but this is #3
//please rate
#include <stdio.h>
float add(float*,float*);
float subtract(float*,float*);
float multiply(float*,float*);
float divide(float*,float*);
float main(){
float num1,num2;
char op;
float flag=0;
do{
printf("Enter number, operator, number ");
scanf("%f %c %f",&num1, &op, &num2);
switch(op){
case '+':
printf("= %.2f ",add(&num1,&num2));
break;
case '-':
printf("= %.2f ",subtract(&num1,&num2));
break;
case '*': case 'x':
printf("= %.2f ",multiply(&num1,&num2));
break;
case '/': case '\':
printf("= %.2f ",divide(&num1,&num2));
break;
default:
printf("An invalid operator was entered. ");
flag=1;
}
}while(flag!=1);
system("pause");
return 0;
}
float add(float *num1,float *num2){
return (*num1) + (*num2);
}
float subtract(float *num1,float *num2){
return (*num1) - (*num2);
}
float multiply(float *num1,float *num2){
return (*num1) * (*num2);
}
float divide(float *num1, float *num2){
if(*num2!=0)
return (*num1) / (*num2);
else
return -999999; //error
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.