Question

In: Computer Science

C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage...

C program help

1. Write a program to compute the Mileage given by a vehicle.

Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works.


2. How to initialize an array of size 5 using an initializer list and to compute it’s sum
How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum

3. Program to compute the car insurance premium for a person based on their age and the number of tickets they have received. The following table explains how to perform the ticket computation:
If Person's Age Is

Then Insurance Cost Is

Less than 21

$1500 + $250 x number of tickets

From 21 through 24

$1200 + $250 x number of tickets

25 or older

$1000 + $200 x number of tickets

Print the person’s age, number of tickets and the computed insurance cost.

Solutions

Expert Solution

1.

#include <stdio.h>

int main(){
double oldOdometer, newOdometer, gallonsGas;
printf("Enter the old odometer reading: ");
scanf("%lf", &oldOdometer);
printf("Enter the new odometer reading: ");
scanf("%lf", &newOdometer);
printf("Enter the number of gallons: ");
scanf("%lf", &gallonsGas);
double mileage = (newOdometer - oldOdometer) / gallonsGas;

printf("The mileage is: %lf\n", mileage);
}

2.

#include <stdio.h>

int main(){
int arr[] = {1, 2, 3, 4, 5};
int sum = 0, i;
for(i = 0; i < 5; i++) {
sum += arr[i];
}
printf("Sum is: %d\n", sum);
}

---------------------------------------------

#include <stdio.h>

int main(){
int arr[5];
int sum = 0, i;
for(i = 0; i < 5; i++) {
arr[i] = 2 * (i + 1);
sum += arr[i];
}
printf("Sum is: %d\n", sum);
}

3.

#include <stdio.h>

int main(){
int tickets, age;
printf("Enter the age: ");
scanf("%d", &age);
printf("Enter the number of tickets received: ");
scanf("%d", &tickets);
double totalCost = 0;
if(age < 21){
totalCost = 1500 + 250 * tickets;
} else if(age < 24) {
totalCost = 1200 + 250 * tickets;
} else {
totalCost = 1000 + 200 * tickets;
}
printf("Age: %d, Insurance cost: %lf\n", age, totalCost);
}


Related Solutions

Help with a c Program to compute the car insurance premium for a person based on...
Help with a c Program to compute the car insurance premium for a person based on their age and the number of tickets they have received. The following table explains how to perform the ticket computation: If Person's Age Is Then Insurance Cost Is Less than 21 $1500 + $250 x number of tickets From 21 through 24 $1200 + $250 x number of tickets 25 or older $1000 + $200 x number of tickets Print the person’s age, number...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
Program in C++ **********Write a program to compute the number of collisions required in a long...
Program in C++ **********Write a program to compute the number of collisions required in a long random sequence of insertions using linear probing, quadratic probing and double hashing. For simplicity, only integers will be hashed and the hash function h(x) = x % D where D is the size of the table (fixed size of 1001). The simulation should continue until the quadratic hashing fails.*********
Write a C++ program to help the Administration of a football league to manipulate the list...
Write a C++ program to help the Administration of a football league to manipulate the list of players registered in different teams. There are 26 teams participating in the league, each is denoted by a letter in the range A to Z. Each team can have 11 players at most. The information of all teams' players are stored in a text file named 'players.dat'. Each line from the input file contains the details of one player; where the player's details...
Help with c program that will have a system pause at the end. 1. Program to...
Help with c program that will have a system pause at the end. 1. Program to compute the car insurance premium for a person based on their age and the number of tickets they have received. The following table explains how to perform the ticket computation: If Person's Age Is: Then Insurance Cost Is- Less than 21 $1500 + $250 x number of tickets From 21 through 24 $1200 + $250 x number of tickets 25 or older $1000 +...
in C++ Write a program to compute the current and the power dissipation in an AC...
in C++ Write a program to compute the current and the power dissipation in an AC circuit that has four resistors R1, R2, R3, and R4 in parallel. The voltage source is V. Test your solution with various voltage levels and resistor values. Execute and submit the program and the results in screen captures. Please note that the equivalent resistor is given by 1/Rtotal = 1/R1 + 1/R2 + 1/R3 + 1/R4 and the current I is given by I...
write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
write c++ program that takes the depth ( in kilometer) inside the earth to compute and...
write c++ program that takes the depth ( in kilometer) inside the earth to compute and display the temperature at the depth in degrees celsius and fahrenheit. the relevant formulas are: celsius+ 10 x depth + 20 fahrenheit = 9/5 celsius + 23
Write a C++ program that creates a base class called Vehicle that includes two pieces of...
Write a C++ program that creates a base class called Vehicle that includes two pieces of information as data members, namely: wheels (type int) weight (type float) Program requirements (Vehicle class): Provide set and a get member functions for each data member. Your class should have a constructor with two parameters (one for each data member) and it must use the set member functions to initialize the two data members. Provide a pure virtual member function by the name displayData()...
write a program in c++ that opens a file, that will be given to you and...
write a program in c++ that opens a file, that will be given to you and you will read each record. Each record is for an employee and contains First name, Last Name hours worked and hourly wage. Example; John Smith 40.3 13.78 the 40.3 is the hours worked. the 13.78 is the hourly rate. Details: the name of the file is EmployeeNameTime.txt Calculate the gross pay. If over 40 hours in the week then give them time and a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT