Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that sequentially displays on screen the contents of all of the

ID: 3670130 • Letter: W

Question

Write a program that sequentially displays on screen the contents of all of the files listed in the command line. Use argc to control a loop.

Write a program that creates a structure template with the following data fields. The program should then prompt the user to enter the data to populate the structure. Finally, use printf() to display the information entered by the user.

Account number

Account owner street address (string)

Account owner city/state (string)

Account owner zip code

Account balances

Account credit limit

Account name

Write a program that converts a user entered temperature in Fahrenheit to Celsius incorporating three modules and functions named as identified below. The user entered Fahrenheit temperature is to be passed as an argument to the function named convert() in the module "conversion.c". The calculated Celsius value is to be return by the function and the result displayed to the user in the function main() :

convert_driver.c - contains the function main() and the user interface

conversion.h - contains the prototype for a function named convert()

convertsion.c - contains the function definition for convert()

Write a calculator program that adds and subtracts. Prompt the user to enter two values and select an operation to perform. Incorporate a program with five modules and functions named as follows:

calc_driver.c - contains the function main() and the user interface

addition.h - contains the prototype for a function named add()

addition.c - contains the function definition for add()

subtraction.h - contains the prototype for a function named subtract()

subtraction.c - contains the function definition for subtract()

Explanation / Answer

/************************************************
   * Description: Write a program that sequentially
   * displays on screen the contents of all of the
   * files listed in the command line. Use argc to
   * control a loop.
   *************************************************/
#include <stdio.h>
int main(int argc, char const *argv[]) /* for command line arguments */
{
   int i;
   int ch;
   FILE *fp; /*file pointer*/
   printf("This program outputs the contents of files. "
       "There are special markers for START/END of each file, indicated by double asteriks '**' and a special message ");
   if (argc == 1)
   {
       printf("!!ERROR!! You need to include file names in the command line when executing this program! ");
       printf("This program outputs the contents of files, if you don't give me any files to output, my existence is meaningless! ");
       printf("!!END!! ");
   }
   for (i = 1; i < argc; i++) /* because argv[0] would be the file name, we start at i = 1,
   using argc as a test expression so that we don't try to read a file that's not even there*/
   {
       fp = fopen(argv[i], "r"); /* opens file pointed to by fp in text mode, replace "r" with "rb" for binary mode */
       printf(" **START OF FILE %d NAMED "%s"** ", i, argv[i]);
       while((ch = getc(fp)) != EOF) /* while getc has not reached the end of the file pointed to by fp*/
           putc(ch, stdout); /* output character obtained by getc to the stdout, in this case the screen*/
       fclose(fp); /* close the file */
       printf("**END OF FILE %d NAMED "%s"** ", i, argv[i]);
       /* line 28 and 32 of the source code were put in to make it clear to the user when each file starts and stops
       I did this because I notcied during testing that not all files end with a new line, so sometimes the last line
       of the one file and the first line of another file can appear on the same line. */
   }
   return 0;
}

output

This program outputs the contents of files.                                                                                                                 
There are special markers for START/END of each file, indicated by double asteriks '**' and a special message                                               
!!ERROR!!                                                                                                                                                   
You need to include file names in the command line when executing this program!                                                                             
This program outputs the contents of files, if you don't give me any files to output, my existence is meaningless!                                          
!!END!!                                                                                                                                                     

/************************************************
   * Write a program that converts a user entered
   * temperature in Fahrenheit to Celsius
   * incorporating three modules and functions named
   * as identified below.
   * The user entered Fahrenheit temperature is to
   * be passed as an argument to the function named
   * convert() in the module "conversion.c".
   * The calculated Celsius value is to be return by
   * the function and the result displayed to the user
   * in the function main() :
   * a.   > convert_driver.c - contains the function main() and the user interface <
   * b.   conversion.h - contains the prototype for a function named convert()
   * c.   convertsion.c - contains the function definition for convert()
   * NOTE: YOU NEED TO COMPILE WITH convertsion.c AS WELL AS HAVE conversion.h IN
   * THE SAME LOCAL DIRECTORY AS THIS SOURCE CODE.
   *************************************************/
convert_driver.c

   #include <stdio.h>
#include "conversion.h"
int main(void)
{
   float fahr;
   float cels;
   printf("Enter your tempurature in Fahrenheit: ");
   scanf("%f", &fahr);
   cels = convert(fahr);
   printf("%f Fahrenheit = %f Celsius ", fahr, cels);

   return 0;
}

conversion.h

//conversion.h - contains the prototype for a function named convert()

float convert(const float fahr); //fahr is const because the value should not be modified by the function


convertsion.c

//convertsion.c - contains the function definition for convert()
float convert(const float fahr) //extern because this function is in
{
   float cels;
   cels = (fahr-32) * (5.0/9.0);
   return cels;
}


output

Enter your tempurature in Fahrenheit:                                                                                                                       
25                                                                                                                                                          
25.000000 Fahrenheit = -3.888889 Celsius  


/************************************************
   * Write a calculator program that adds and subtracts. Prompt the user to enter two values and select an operation to perform.
   * Incorporate a program with five modules and functions named as follows:
   * a.   > calc_driver.c - contains the function main() and the user interface <
   * b.   addition.h - contains the prototype for a function named add()
   * c.   addition.c - contains the function definition for add()
   * d.   subtraction.h - contains the prototype for a function named subtract()
   * e.   subtraction.c - contains the function definition for subtract()
   * NOTE:
   * calc_driver.c, addition.c, and subtraction.c need to be compiled together.
   * addition.h and subtraction.h both need to be in the same local directory
   * as the source code files.
   *************************************************/
calc_driver.c

   #include <stdio.h>
#include <ctype.h>
#include "addition.h"
#include "subtraction.h"
int main(void)
{
   float first;
   float second;
   float result;
   char choice;

   printf("This program performs an operation of addition or subtraction on 2 numbers that you will provide. Please enter the first number ");

   scanf("%f", &first);

   printf("...Now please enter the second number. ");

   scanf("%f", &second);

   while(getchar() != ' ') /* clear newline from buffer */
       continue;

   printf(" Now please enter the letter corresponding to the operation you would like to perform: ");
   printf(" a: add %.2f to %.2f ", first, second);
   printf(" b: subtract %.2f from %.2f ", second, first);
   printf("Your choice: _");

   scanf("%c", &choice);

   while(choice != 'a' && choice != 'b') /* input verification, making sure that choice == a or b before moving to next segment of code*/
   {
       printf("Oops! please enter a, or b try again:"); /* warning message and fancy beep */
       scanf("%c", &choice);
       while(getchar() != ' ') /* clear newline from buffer */
           continue;
   }

   switch(choice){
       case 'a': result = add(first, second);
       printf(" %.2f + %.2f = %.2f ", first, second, result);
       break;
       case 'b': result = subtract(first, second);
       printf(" %.2f - %.2f = %.2f ", first, second, result);
       break;
       }

   printf(" Done. ");

   return 0;
}                                                                                                                

addition.c

float add(const float num1, const float num2)
{
   return num1 + num2;

}

addition.h


float add(const float num1, const float num2);

subtraction.c

float subtract(const float num1, const float num2)
{
   return num1 - num2;
}

subtraction.h

float subtract(const float num1, const float num2);

output

This program performs an operation of                                                                                                                       
addition or subtraction on 2 numbers that you will provide.                                                                                                 
Please enter the first number                                                                                                                               
5                                                                                                                                                           
...Now please enter the second number.                                                                                                                      
6                                                                                                                                                           
                                                                                                                                                            
Now please enter the letter corresponding to the operation you would like to perform:                                                                       
        a: add 5.00 to 6.00                                                                                                                                 
        b: subtract 6.00 from 5.00                                                                                                                          
Your choice: a                                                                                                                                              
                                                                                                                                                            
5.00 + 6.00 = 11.00                                                                                                                                         
                                                                                                                                                            
Done.                                                                                                                                                       

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote