1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Lab 2 variables

3 1 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Course Programming Fundamentals (C language) 1 LAB 2 – Variables Main content 1 Get used to variable declarations 2 Get used to value inputs and outputs from variables 3 Start simple data processing 4[.]

Course: Programming Fundamentals (C language) LAB – Variables Main content: Get used to variable declarations Get used to value inputs and outputs from variables Start simple data processing Check coding styles Practice: Get used to variable declarations 1.1 Re-write the following C program in the editor of your IDE tool and then compile and run its corresponding executable program For each warning/error returned in the IDE’s messages, fix it till the program can be executed 1.2 Start a C program and define several variables and constants appropriate for the following use contexts: 1.2.1 The side length of a square 1.2.2 PI number for circle-related calculation 1.2.3 The number of elements in a collection 1.2.4 Distance in kilometer in movement by taxi from location A to location B 1.2.5 The unit price of a kilometer in taxi payment which is 12000 1.2.6 The fixed number of the students in our class which is 20 1.2.7 Information about your course: course name, course id, midterm exam grade, and final exam grade 1.2.8 Information about you and your purchase card for payment processing: your full name, card id, and its expiration date Get used to value inputs and outputs from variables 2.1 Which scanf statements are valid? For those invalid, fix them so that they are valid for receiving values from the keyboard 2.1.1 Receive a number corresponding to the current temperature in oC double temperature; scanf("%lf", &temperature); 2.1.2 Receive two positive integer numbers corresponding to class identifier and group identifier unsigned int cID, gID; scanf("%4u\t%2u", cID, gID); 2.1.3 Receive two strings corresponding to a title and a last name of a customer char title[10], name[20]; scanf("%3s %s", title, name); 2.1.4 Receive two floating-point numbers corresponding to your midterm exam grade and final exam grade float midGrd, fnlGrd; scanf("%lf %lf", &midGrd, &fnlGrd); 2.2 Write the printf statements to print the values of the aforementioned variables in question 2.1 with the formats appropriate for their data types Start simple data processing 3.1 Write a C program to calculate the area inside a circle whose radius is input by a user and also calculate the area inside the square that covers the circle After that, calculate their circumferences 3.2 Write a C program to calculate the arithmetic mean, weighted arithmetic mean, geometric mean, and harmonic mean of floating-point numbers input by the user It is given the weights of input numbers for the calculation of their weighted arithmetic mean as follows: w1 = 2; w2 = 3; w3 = 1.5; w4 = 3.2; w5 = 5.3 Print all the mean values in the form of "%.2f" 3.3 Write a C program to calculate a semester GPA grade of a student and print the information as follows Grade is used to keep a grade of a corresponding course that a student has obtained after studying the course Grades are shown in a 4-scale grading system: ‘A’ for grade in [8.5, 10], ‘B’ for grade in [6.5, 8.5), ‘C’ for grade in [5.0, 6.5), and ‘D’ for grade in [0, 5) Calculate a semester GPA of student S1 using a weighted mean such as: GPA  grade1* credit1 grade2* credit2 grade3* credit3 credit1 credit2 credit3 It is supposed that student S1 has got 8, 7.5, and 8.8 for grade1 of Course with credits, grade2 of Course with credits, and grade3 of Course with credits, respectively GPA is then calculated as follows: GPA  *  7.5 *  8.8 *  8.17 33 Now receive the grades of student S1 from your keyboard along with the credit of each course If GPA < 5.0 then print “Umh! Umh! Umh!” If GPA >= 5.0 and GPA < 8.0 then print “You are a good student.” Otherwise, print “Wow! Wow! Wow!” Please note that grades are from to 10 If an invalid grade is input, the program won’t proceed with GPA calculation Check coding styles For each C program that you have written, check coding styles with the following points: - How have you used blank lines? - How have you used tabs for alignment? - How have you used comments in your source code files? - Above all, how about your naming conventions? What have you named in your source code files?

Ngày đăng: 11/04/2023, 18:46

Xem thêm:

w