a student’s letter grade is calculated according to the following schedule.write a c program that ac
时间: 2023-05-02 20:00:41 浏览: 124
为了计算学生的成绩,在以下计算表中给出了成绩分布规则。请编写一个C语言程序来计算学生的成绩。
90 <= grade <= 100: A
80 <= grade <90: B
70 <= grade <80: C
60 <= grade <70: D
grade <60: F
相关问题
A car rental company rents out a variety of cars and coaches and its rental rates are calculated on a daily basis. The relevant information of vehicle is shown in the following form. You need to develop a vehicle rental system according to the following requirements. (1) Design a simple console interactive interface to provide users with the related information about this vehicle rental system including vehicle models, specific information, daily rent and discount information so that the user can make further choices. (2) After understanding the relevant information, the user can input the relevant information of the vehicle which he or she wants to rent through the console program. (3) The program calculates the rent that the user needs to pay and informs the user through the console program. (4) You need to deal with the illegal information input by users through the console with some rules and prompt the corresponding error reason.For example, the user cannot input a negative value for the number of parking days.You need to consider as many misinput cases as possible. Please submit program code and the screenshot of the program output in the answer
I'm sorry, but as an AI language model, I am not able to submit program code or screenshots of program output. However, I can provide you with guidance on how to approach this problem.
To develop a vehicle rental system, you can use a programming language like Python and create a console-based interface using the built-in input and print functions. Here is a general outline of how you can implement the system:
1. Create a list of vehicle models with their specific information (e.g., brand, model, seating capacity, fuel type, etc.), daily rent, and discount information (e.g., 10% off for renting more than 7 days).
2. Display the list of vehicle models and their information to the user using the print function.
3. Prompt the user to input the model of the vehicle they want to rent, as well as the number of days they want to rent it for, using the input function.
4. Validate the input to ensure that the user has entered a valid model and a positive number of days. If the input is invalid, display an error message and prompt the user to input again.
5. Calculate the rent based on the daily rent and any applicable discounts, and display the total rent to the user using the print function.
6. End the program.
Here is some example code to get you started:
```
# Define the list of vehicle models and their information
vehicles = [
{
'model': 'Sedan',
'info': 'Brand: Honda | Model: Civic | Seating Capacity: 5 | Fuel Type: Gasoline',
'daily_rent': 50,
'discount': 0.1
},
{
'model': 'SUV',
'info': 'Brand: Toyota | Model: RAV4 | Seating Capacity: 7 | Fuel Type: Gasoline',
'daily_rent': 70,
'discount': 0.15
},
{
'model': 'Coach',
'info': 'Brand: Mercedes | Model: Tourismo | Seating Capacity: 50 | Fuel Type: Diesel',
'daily_rent': 300,
'discount': 0.2
}
]
# Display the list of vehicle models and their information
print('Available Vehicles:')
for vehicle in vehicles:
print(vehicle['model'])
print(vehicle['info'])
print('Daily Rent:', vehicle['daily_rent'])
print('Discount:', vehicle['discount'])
print()
# Prompt the user to input the model and number of days
model = input('Enter the model of the vehicle you want to rent: ')
days = input('Enter the number of days you want to rent it for: ')
# Validate the input
valid_input = False
while not valid_input:
try:
days = int(days)
if days <= 0:
print('Error: Number of days must be positive')
else:
for vehicle in vehicles:
if vehicle['model'] == model:
rent = vehicle['daily_rent'] * days * (1 - vehicle['discount'])
print('Total Rent:', rent)
valid_input = True
break
else:
print('Error: Invalid vehicle model')
break
except ValueError:
print('Error: Number of days must be an integer')
break
```
This is just a basic example, and you may need to customize it further to meet your specific requirements and handle more edge cases.
Write the C program according to the following menu interface - student information management system; 1)Enter student information: first enter the number of students, and then enter the corresponding information into the array according to the number of students; 2)Student information includes student number, name, gender, three course scores and total scores; Student number, name, gender and grades of three courses need to be entered from the keyboard, and the total score is calculated by the program, not by the user himself. 3)The display results (student information) shall be displayed in the form of list, paying attention to aesthetics; 4)Necessary fault tolerance measures shall be taken. For example, the score of each subject shall be between 0-100. If the input is wrong, the user shall be prompted to re-enter.
Sure, here's a C program that implements the student information management system with the menu interface you specified:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct student {
int id;
char name[50];
char gender[10];
int scores[3];
int total_score;
};
int read_int() {
int n;
while (scanf("%d", &n) != 1) {
printf("Invalid input, please enter an integer: ");
scanf("%*[^\n]");
}
scanf("%*[^\n]");
scanf("%*c");
return n;
}
void read_string(char* str, int max_len) {
char* p = fgets(str, max_len, stdin);
if (p == NULL) {
printf("Invalid input, please try again: ");
read_string(str, max_len);
} else {
int len = strlen(str);
if (len > 0 && str[len - 1] == '\n') {
str[len - 1] = '\0';
}
}
}
void enter_student_info(struct student* students, int num_students) {
printf("Enter student information:\n");
for (int i = 0; i < num_students; i++) {
printf("Student %d:\n", i + 1);
printf(" ID: ");
students[i].id = read_int();
printf(" Name: ");
read_string(students[i].name, sizeof(students[i].name));
printf(" Gender: ");
read_string(students[i].gender, sizeof(students[i].gender));
for (int j = 0; j < 3; j++) {
printf(" Score in course %d: ", j + 1);
students[i].scores[j] = read_int();
while (students[i].scores[j] < 0 || students[i].scores[j] > 100) {
printf("Invalid score, please enter a score between 0 and 100: ");
students[i].scores[j] = read_int();
}
}
students[i].total_score = students[i].scores[0] + students[i].scores[1] + students[i].scores[2];
}
}
void display_student_info(const struct student* students, int num_students) {
printf("ID Name Gender Course 1 Course 2 Course 3 Total\n");
printf("----------------------------------------------------------------\n");
for (int i = 0; i < num_students; i++) {
printf("%-5d%-19s%-8s%-9d%-9d%-9d%-5d\n", students[i].id, students[i].name, students[i].gender, students[i].scores[0], students[i].scores[1], students[i].scores[2], students[i].total_score);
}
}
int main() {
struct student students[MAX_STUDENTS];
int num_students = 0;
while (1) {
printf("Student information management system:\n");
printf("1) Enter student information\n");
printf("2) Display student information\n");
printf("3) Exit\n");
printf("Please enter a choice (1-3): ");
int choice = read_int();
switch (choice) {
case 1:
printf("Enter the number of students: ");
num_students = read_int();
while (num_students < 1 || num_students > MAX_STUDENTS) {
printf("Invalid number of students, please enter a number between 1 and %d: ", MAX_STUDENTS);
num_students = read_int();
}
enter_student_info(students, num_students);
printf("Student information entered successfully.\n");
break;
case 2:
if (num_students == 0) {
printf("No student information entered yet.\n");
} else {
display_student_info(students, num_students);
}
break;
case 3:
printf("Exiting...\n");
exit(0);
default:
printf("Invalid choice, please enter a number between 1 and 3.\n");
}
}
return 0;
}
```
This program uses a struct to store the information of each student, and an array of structs to store the information of all students. The `read_int()` function and `read_string()` function are used for input validation, to make sure that the user enters valid integers and strings. The `enter_student_info()` function prompts the user to enter the information of each student, validates the scores, and calculates the total score. The `display_student_info()` function displays the student information in a formatted table. The `main()` function implements the menu interface and calls the other functions based on the user's choice. The program also includes some fault tolerance measures, such as checking the number of students entered, checking the validity of the scores, and handling invalid input.
阅读全文