Question

In: Computer Science

Write the 5 programs and submit source.c and csis.txt files. Stegman p. 240 9th edition. 1....

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.

Solutions

Expert Solution

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


Related Solutions

book: Fundamentals of Corporate Finance Alternate Edition (9th Edition) Conch Republic Electronics, Part 1 Conch Republic...
book: Fundamentals of Corporate Finance Alternate Edition (9th Edition) Conch Republic Electronics, Part 1 Conch Republic Electronics is a small electronics manufacturer located in Key West, Florida. The president of the company is Shelley Couts, who inherited the business. When the company was founded more than 70 years ago, it repaired radios and other devices for the home. With the passage of time, the company expanded to the manufacturing areas and today is a reputed producer of various electronic items....
Using Financial Accounting Information (9th Edition) Decision Case 13-5: Acquisition Decision Diversified Industries is a large...
Using Financial Accounting Information (9th Edition) Decision Case 13-5: Acquisition Decision Diversified Industries is a large conglomerate that is continually in the market for new acquisitions. The company has grown rapidly over the last ten years through buyouts of medium-size companies. Diversified does not limit itself to companies in any one industry, but looks for firms with a sound financial base and the ability to stand on their own financially.   The president of Diversified recently told a meeting of the...
Write C++ program (submit the .cpp,.h, .sln and .vcxproj files) Problem 1. Generate 100 random numbers...
Write C++ program (submit the .cpp,.h, .sln and .vcxproj files) Problem 1. Generate 100 random numbers of the values 1-20 in an input.txt. Now create a binary search tree using the numbers of the sequence. The tree set should not have any nodes with same values and all repeated numbers of the random sequence must be stored in the node as a counter variable. For example, if there are five 20s’ in the random sequence then the tree node having...
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp -...
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp - main() function (2) Build the ContactNode class per the following specifications: Parameterized constructor. Parameters are name followed by phone number. Public member functions InsertAfter() (2 pts) GetName() - Accessor (1 pt) GetPhoneNumber - Accessor (1 pt) GetNext() - Accessor (1 pt) PrintContactNode() Private data members string contactName string contactPhoneNum ContactNode* nextNodePtr Ex. of PrintContactNode() output: Name: Roxanne Hughes Phone number: 443-555-2864 (3) In main(),...
In Java: (1) Create two files to submit: ItemToBuy.java - Class definition ShoppingCartDriver.java - Contains main()...
In Java: (1) Create two files to submit: ItemToBuy.java - Class definition ShoppingCartDriver.java - Contains main() method Build the ItemToBuy class with the following specifications: Private fields String itemName - Initialized in the nor-arg constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 No-arg Constructor (set the String instance field to "none") Public member methods (mutators & accessors) setName() & getName() setPrice() & getPrice() setQuantity() & getQuantity() toString()...
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp -...
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp - main() function Build the ItemToPurchase class with the following specifications: Default constructor Public class functions (mutators & accessors) SetName() & GetName() (2 pts) SetPrice() & GetPrice() (2 pts) SetQuantity() & GetQuantity() (2 pts) Private data members string itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 (2)...
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2....
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2. ????ℎ??????ℎ??????. ??? You are being asked to write a class for simple weather data storage. Each instance of the class will hold data for exactly one month (30 days). Each day’s weather will be classified as either rainy (‘R’), cloudy (‘C’), or sunny (‘S’). To achieve this, your class will contain a character array of length 30. The class will provide three functions to...
Reference Material: Chapters 13-21 Spiceland Intermediate Accounting 9th Edition J David Spiceland Question 1: Identify 3...
Reference Material: Chapters 13-21 Spiceland Intermediate Accounting 9th Edition J David Spiceland Question 1: Identify 3 areas where the accounting appears to be most reasonable and useful to investors and creditors. State the accounting treatment and the reasoning in identifying the standard as strong or weak. Question 2: Identify 3 areas where you believe accounting is confusing, makes less sense and lack of value to investors and creditors. State the accounting treatment and the reasoning in identifying the standard as...
Reference Material: Chapters 13-21 Spiceland Intermediate Accounting 9th Edition J David Spiceland Item 1: Identify 3...
Reference Material: Chapters 13-21 Spiceland Intermediate Accounting 9th Edition J David Spiceland Item 1: Identify 3 areas where the accounting appears to be most reasonable and useful to investors and creditors. State the accounting treatment and the reasoning in identifying the standard as strong or weak. Item 2: Identify 3 areas where you believe accounting is confusing, makes less sense and lack of value to investors and creditors. State the accounting treatment and the reasoning in identifying the standard as...
C (1) Create three files to submit: ItemToPurchase.h - Struct definition and related function declarations ItemToPurchase.c...
C (1) Create three files to submit: ItemToPurchase.h - Struct definition and related function declarations ItemToPurchase.c - Related function definitions main.c - main() function Build the ItemToPurchase struct with the following specifications: Data members (3 pts) char itemName [ ] int itemPrice int itemQuantity Related functions MakeItemBlank() (2 pts) Has a pointer to an ItemToPurchase parameter. Sets item's name = "none", item's price = 0, item's quantity = 0 PrintItemCost() Has an ItemToPurchase parameter. Ex. of PrintItemCost() output: Bottled Water...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT