C programming You are the head programmer at Cool School University. You are tas
ID: 3867286 • Letter: C
Question
C programming
You are the head programmer at Cool School University. You are tasked with writing a program to take input for a student and print the cost of attending classes this semester. The unit cost is $100 (use a preprocessor directive to define this as a constant value). Furthermore, if a student is enrolled in more than 12 units, they receive a $10 discount for every unit they take over 12. Students that live on campus are charged an extra $1000 for housing costs. Your tasks are to get a student name with spaces (char array), y or n (char) for living on campus, and number of units enrolled (int) from the console. Calculate the amount due using the criterion above and print the output to the console window. Use the same data types listed above.
- Include a student struct. Data members should include char array (or char*) for name, char for housing response, and int for units taken at a minimum. The getInput function should be pass by reference (struct student*). The others, depending on how they are coded, can be pass by value (struct student). Use the struct in your code.
- Write a function called getInput that returns void and takes char* (for name), int (for name length – may be optional for some), char* (for y or n response), and int* (for units). In the body of the function prompt the user and store input for a student name, char (y or n) depending on if they live on campus, and int for number of units. Remember when using scanf with pointers no ampersand is needed. fgets/gets stays the same (no ampersand).
e.g. getInput(names[i], nameLen, &onCampus, &units);
You can break this into smaller functions like getName, getHousing, and getUnits but they must be pass by reference.
- Write a function called printOutput that returns void and takes a const char* (for name) and const int (for tuition cost). In the body of the function print a label, student name and new line followed by a label and the amount due.
e.g. printOutput(names[i], tuitionCost[i]);
Do NOT use global variables. The global constants defined in previous programs are OK.
Explanation / Answer
include <stdio.h>
include <stdlib.h>
define unitcost $100
define discount $10
define housing $1000
int main() { int Y; int N;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.