In: Computer Science
Write the 5 programs and submit source.c and csis.txt files. Stegman p. 240 9th edition.
1. Write a function passed a char and outputs whether it is a vowel or consonant.
2. Write a function passed an int month and outputs the name of the month and the number of days in that month.
3.Write a function to determine if a triangle is equilateral, isosceles or scalene.
4. Write a function that accepts 3 int variables and returns the largest.
5. Write a function prototype: void timeUpdate(int *hour, int *min, int *sec); which updates the time by one second.
For question 5.
Use call by reference, and print the output in main(). Use call by reference. You do not return a value in a return statement or use printf() or scanf() in the function. Do not print results in the function. The variables hour sec min are modified and changed in the function and remain changed after the return. We had a Short Assignment: Call by reference using the area of a circle to illustrate that. This concept applies to the Checking Account Lab.
This assignment is write 5 functions and show their outputs as in other short assignments and labs. Only .c, .txt and .h file are accepted.
functions.h
void checkChar(char c){
if(c=='a' || c=='e' || c=='i' || c=='o' ||
c=='u')
printf("%c - Vowel", c);
else
printf("%c - Consonant", c);
}
void month(int m){
if(m==1)
printf("January: ");
else if(m==2)
printf("February: ");
else if(m==3)
printf("March: ");
else if(m==4)
printf("April: ");
else if(m==5)
printf("May: ");
else if(m==6)
printf("June: ");
else if(m==7)
printf("July: ");
else if(m==8)
printf("August: ");
else if(m==9)
printf("September: ");
else if(m==10)
printf("October: ");
else if(m==11)
printf("November: ");
else if(m==12)
printf("December: ");
if(m==1 || m==3
||m==5||m==7||m==8||m==10||m==12)
printf("31 days");
else if(m==2)
printf("28 days");
else if(m==4 ||m==6||m==9||m==11)
printf("30 days");
}
void checkTriangle(int a, int b, int c){
if(a==b && b==c)
printf("Equilateral
triangle");
else if(a!=b && b!=c && a!=c)
printf("Scalane triangle");
else
printf("Isosceles triangle");
}
int largest(int a, int b, int c){
if(a>b && a>c)
return a;
if(b>a && b>c)
return b;
else
return c;
}
void timeUpdate(int *hour, int* min, int* sec){
//Incrment second, if sec becomes 60, then adjust min and hour
accordingly
*sec += 1;
if(*sec >59){
*sec = 0;
*min += 1;
if(*min >59){
*hour +=
1;
*min = 0;
}
}
}
main.c
#include<stdio.h>
#include "functions.h"
int main(){
checkChar('a');
printf("\n");
checkChar('z');
printf("\n");
month(1);
printf("\n");
month(2);
printf("\n");
month(11);
printf("\n");
month(12);
printf("\n");
checkTriangle(1,1,1);
printf("\n");
checkTriangle(2,2,3);
printf("\n");
printf("Largest of 2, 3, 99 is %d\n",
largest(2,3,99));
int hour = 5, min = 59, sec = 59;
timeUpdate(&hour, &min, &sec);
printf("%d %d %d\n", hour, min, sec);
timeUpdate(&hour, &min, &sec);
printf("%d %d %d\n", hour, min, sec);
return 0;
}