Question

In: Computer Science

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 + $200 x number of tickets

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

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

Mileage = (new_odometer – old_odometer)/(gallons_gas)

Program illustrating how ‘for’ loop works.

3. Program to find the factorial of a number using recursive function

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

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...
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 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...
Below is my C++ program of a student record system. I have done the program through...
Below is my C++ program of a student record system. I have done the program through structures. Please do the same program using classes this time and dont use structures. Also, please make the menu function clean and beautiful if you can. So the output will look good at the end. Thanks. #include<iostream> #include<string> using namespace std; struct StudentRecord {    string name;    int roll_no;    string department;    StudentRecord *next; }; StudentRecord *head = NULL; StudentRecord *get_data() {...
1) Now that you have learned some of the basic principles of organization, pause and think...
1) Now that you have learned some of the basic principles of organization, pause and think about where you have already applied such concepts yourself or when you have been part of an organization that did. 1. Did you find a division of labor necessary and helpful? 2. Were you assigned specific tasks or left on your own to decide what to do? 3. Were promotions based strictly on qualifications, as Weber suggested? What other factors may have been considered?...
1) Now that you have learned some of the basic principles of organization, pause and think...
1) Now that you have learned some of the basic principles of organization, pause and think about where you have already applied such concepts yourself or when you have been part of an organization that did. 1. Did you find a division of labor necessary and helpful? 2. Were you assigned specific tasks or left on your own to decide what to do? 3. Were promotions based strictly on qualifications, as Weber suggested? What other factors may have been considered?...
C++ in one program that ends with return 0} at the end f Write a program...
C++ in one program that ends with return 0} at the end f Write a program to calculate the salary paid to its salespersons at Pohanka. The salary is calculated based on a salesperson’s length of employment in years and employment category (full-time employee or part-time employee). The salary calculation rules are as following: 1) If an employee is a part-time employee and worked here for less than 5 years, the salary consists of only the commission amount; 2) If...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Draw the main memory diagram as captured at the end of the C program
FOR C PROGRAMMING LANGUAGE Draw the main memory diagram as captured at the end of the C program (i.e. return 0; statement). Your diagram must clearly shows where str, p1, p2, and p3 are pointing to, when the program terminates. int main(void) { char str[] = "cs111 NYU"; char* p1 = str; p1 ++; char** p2 = &p1; char* p3 = &str[4]; printf("1. str = %s\n", p1); if(p3 - p1 == 4) { printf("2. p1 == p3\n"); } printf("3. char1...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries. Note: The program must loop until the 2nd menu option is chosen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT