Question

SOLVE USING C!!!

Project objective: Conditional statements, loops, reading from file, user defined functions.

**Submit source code (LargeProg1.c) through Canvas

  • One source code file(unformatted text) will be submitted
  • Here is INCOMPLETE code to get started: LargeProg1.cPreview the document
    • The file name must match the assignment
    • The code should be tested and run on a Microsoft compiler before it is uploaded onto Canvas
    • The code must be submitted on time in order to receive credit (11:59PM on the due date)
    • Late submissions will not be accepted or graded
    • All programming assignments are individual work,sharing code is considered cheating
  • Be sure to save the input.txt file into the same directory as source code file (remember to use your Z drive on portal.eng.fau.edu)

How to Submit:

Submit your source code (LargeProg1.c) by clicking the link, attaching your source code (LargeProg1.c), and clicking submit.

This should be one file and MUST be the file with the .c extension. Submitting the incorrect file may result in no credit for the assignment.

Instructions:

Write a fully executable code.

The program should give the user 3 options:

Option 1: Calculate and display the day of the week of a given date.

Option 2: Calculate and display the principal on a savings account after a given number of years for compounded interest. Compounded interest means that you receive interest on your interest, i.e. if you have $100 on the bank that pays 2% interest, after the first year you will have $102 and after the second year you will have $104.04, the $0.04 being the interest on the interest.

Option 3: Calculate and display the principal on a savings account after a given number of years for simple interest.

After the user chose an option execute the option and ask the user if (s)he wants to end the program. If not, start the program again from the beginning. Implement all options as user defined functions.

Instructions for option 1:

  1. Have the user enter a date (ask separately for the day, month and year). In the following example let us assume that the user entered the date October 11, 1996 (note that the user should enter the date in numerical format).
  2. The user-defined function for option 1 should take this date as an input and output the day of the week in the following format: 0 for Sunday, 1 for Monday, 2 for Tuesday etc.
  3. Use a reference date of which you know the weekday, e.g. June 1, 2019 is a Saturday.
  4. Calculate the number of days between the reference date and the user entered date:
    1. Iterate over the full years and count the days in the full years (take into account leap years (see leap year rules below)). In the example your program would iterate from 1997 to 2018 (inclusive) and add 365 days for each year or 366 if it is a leap year. So we would add 365 for all years except for 2000, 2004, 2008, 2012, 2016 where we would add 366. 17*365+5*366=8035 days.
    2. Count the number of days in the months remaining in the year of the first date and in the year of the last date. In the example these are November and December for the first date and January, February, March, April, May before the second date. Hence add 30 + 31 = 61 days from the first date and 31+28+31+30+31= 151 days before the second date. Remember to account for leap years!
    3. Count the number of days in the month of the first date and in the second date. Include the day of interest, but not the day of the reference date. In our example this is 21 days for the first date and 1-1 = 0 days for the second date.
    4. Add all the numbers together to get the total number of days. Here: 8035+61+151+21 = 8268
  5. Divide the number by 7 and determine the remainder. Here: 8268/7 is 1181 with a remainder of 1, so the weekday of the first date is 1 day before Saturday, i.e. Friday. Note that if the user's date is before the reference date as in the example here, the days indicated by the remainder tell you how many weekdays before the reference date the weekday of the user's date is. Otherwise it will give you the weekdays after the reference date.
  6. Make sure to account for the possibility that the user enters a date after the reference date (in the example: June 1, 2019).

Leap year rules:

In the Gregorian calendar three criteria must be taken into account to identify leap years:

  • The year can be evenly divided by 4;
  • If the year can be evenly divided by 100, it is NOT a leap year, unless;
  • The year is also evenly divisible by 400. Then it is a leap year.

Instructions for option 2:

  1. Have the user enter a principal, an interest rate and the number of years.
  2. Take the user entered values as inputs (arguments) for your user-defined function. The function should output the principal after the number of years if the interest is compounded yearly (i.e. interest is added yearly to the bank account).
  3. To calculate the compound interest (formula see below) you will need to use the <math.h> library and the powfunction therein. To calculate the 3434 in C use pow(3,4). This works for decimals as well.
  4. Compound interest formula: A P (1r) A=P(1+r)n where A is the principal after n years, P is the initial principal, r is the yearly interest. Example: If your initial principal is $100 (P=100) and the interest rate is 2% (r=0.02) and you leave it on a bank account where the interest is compounded yearly after 30 years (n=30) you will have A 100(10.02)30 181.14 A=100(1+0.02)30=181.14 , i.e. your principal after 30 years would have almost doubled to $181.14.
  5. Display and return the result.

Instructions for option 3:

  1. Same as for option 2, but use the formula A P (1nr) A=P(1+nr), where A is the principal after n years, P is the initial principal, r is the yearly interest. Example: If your initial principal is $100 (P=100) and the interest rate is 2% (r=0.02) and you leave it on a bank account with simple interest after 30 years (n=30) you will have A 100 (10.02 (30)) 160.00 A=100(1+0.02(30))=160.00 , i.e. you would have $21.14 less than with the compounded interest.

34
A P (1r)"
A 100(10.02)30 181.14
A P (1nr)
A 100 (10.02 (30)) 160.00
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include<math.h>

double main()
{
int option;
printf("enter the option");
scanf("%d",&option);
switch(option)
{
case 1:get_weekday();
break;
case 2:compoundinterest();
break;
case 3:simpleinterest();
break;
default:printf("invalid option");
  
}

return 0;
}
int get_weekday(char * str) {
struct tm;
memset((void *) &tm, 0, sizeof(tm));
if (strptime(str, "%d-%m-%Y", &tm) != NULL) {
time_t t = mktime(&tm);
if (t >= 0) {
return localtime(&t)->tm_wday; // Sunday=0, Monday=1, etc.
}
}
return -1;
}
double compoundinterest()
{
double p;
printf("enter the principal amount");
scanf("%lf",&p);
  
double r;
printf("enter the rate");
scanf("%lf",&r);
int n;
printf("enter the no of years");
scanf("%d",&n);
double a,x;
x=pow((1+r),n);
a=p*x;
printf("The required amount is:%lf\n",a);
  
}
double simpleinterest()
{
double p;
printf("enter the principal amount");
scanf("%lf",&p);
  
double r;
printf("enter the rate");
scanf("%lf",&r);
int n;
printf("enter the no of years");
scanf("%d",&n);
double a;
double x;
x=(1+(n*r));
a=p*x;
printf("The required amount is:%lf\n",a);
}

Add a comment
Know the answer?
Add Answer to:
SOLVE USING C!!! Project objective: Conditional statements, loops, reading from file, user defined functions. **Submit source...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Conditional statements, loops, reading from file, user defined functions.

    # in C Project objective: Conditional statements, loops, reading from file, user defined functions.**Submit source code (prog3.c) through CanvasOne source code file(unformatted text) will be submittedHere is INCOMPLETE code to get started: prog3.cHere is input.txt file: input.txtThe file name must match the assignmentThe code should be tested and run on a Microsoft compiler before it is uploaded onto CanvasThe code must be submitted on time in order to receive credit (11:59PM on the due date)Late submissions will not be accepted or gradedAll...

  • Complete task using python code From definitions file: month = ‘February’ year = 1200 Problem 2:...

    Complete task using python code From definitions file: month = ‘February’ year = 1200 Problem 2: Leap Years (2 Points) Your task is to write a program that takes in both a month and year (defined in the definitions file) and outputs the number of days for that month. It should take into account whether the year is a leap year or not. The resulting number of days in a given month/year combo is to be assigned to the variable...

  • Need help on C++ (User-Defined Function) Format all numerical decimal values with 4 digits after ...

    need help on C++ (User-Defined Function) Format all numerical decimal values with 4 digits after the decimal point. Process and sample run: a) Function 1: A void function that uses parameters passed by reference representing the name of a data file to read data from, amount of principal in an investment portfolio, interest rate (any number such as 5.5 for 5.5% interest rate, etc.) , number of times the interest is compounded, and the number of years the money is...

  • 14.Compound Interest hank account pays compound interest, it pays interest not only on the principal amount...

    14.Compound Interest hank account pays compound interest, it pays interest not only on the principal amount that was deposited into the account, but also on the interest that has accumulated over time. Suppose you want to deposit some money into a savings account, and let the account earn compound interest for a certain number of years. The formula for calculating the balance of the account afer a specified namber of years is The terms in the formula are A is...

  • Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java,...

    Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following:  Ask user to enter Today’s...

  • Write and submit a MIPS Assembly Language program which requests an integer (year) from the user...

    Write and submit a MIPS Assembly Language program which requests an integer (year) from the user and then invokes a function to determine the beginning date and time of each season. The program must be properly documented which includes in file comments. Note: This is a Computer Science/Engineering course, not a Physics/Astronomy course. The exact time is not expected. Approximations are acceptable. Document your calculation process in the report. Basically, the intent is that you store a reference date and...

  • Programming language: PYTHON Prompt: You will be creating a program to show final investment amounts from...

    Programming language: PYTHON Prompt: You will be creating a program to show final investment amounts from a principal using simple or compound interest. First, get a principal amount from the user. Next, ask the user if simple or compound interest should be used. If the user types in anything other than these options, ask again until a correct option is chosen. Ask the user to type in the interest rate as a percentage from 0 to 100%. Finally, ask the...

  • c++ and please add tables and everything and make sure program is complete. Write a menu...

    c++ and please add tables and everything and make sure program is complete. Write a menu driven program, which would compute compound interest and a monthly payment for a loan. The user will be given a choice to display the info on the screen or to a filo Menu will be the following Enter (1) to calculate your loan monthly payment Enter (2) to calculate your loan monthly payment & write to a file Tips: Compound Interest Formula A =...

  • In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops...

    In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops for the input validations required: number of employees(cannot be less than 1) and number of days any employee missed(cannot be a negative number, 0 is valid.) Each function needs a separate flowchart. The function charts are not connected to main with flowlines. main will have the usual start and end symbols. The other three functions should indicate the parameters, if any, in start; and...

  • PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program tha...

    PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file  timeValidation.txt :   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT