Question

In: Computer Science

Assignment (C language, not C ++) Start a new project to store grade information for 5...

Assignment (C language, not C ++)

Start a new project to store grade information for 5 students using structures.

  1. Declare a structure called student_t that contains :
    • First name
    • Last name
    • Student ID Number
    • Percentage grade
    • Letter grade
  2. Create the following functions:

    getStudentInfo(void)- Declares a single student object
    - Uses printf()/scanf() to get keyboard input for Name, SID, and Percentage (not Letter).
    - Returns a single student structure

    calcStudentGrade(student_t *st_ptr)- Takes the pointer to a student (to avoid making a copy)
    - Uses the student's percentage to determine and store their letter grade

    printStudentInfo(student_t *st_ptr)- Takes the pointer to a student (to avoid making a copy)
    - Prints out all of the student information
  3. Declare an array of five students
  4. Using a for loop and getStudentInfo() function, get input of all the students
  5. Using a for loop and calcStudentGrade() function, determine and store all student's letter grades.
  6. Using a for loop and printStudentInfo() function, print all the output of all students.

Example output:

     NAME              SID         SCORE   GRADE
     Hopper, Grace     135792468   97.5%   A
     Turing, Alan      198765432   82.9%   B
     Babbage, Charles  165754329   79.0%   C
     Lovelace, Ida     147632391   92.4%   A
     Neumann, John     200638730   99.0%   A

Solutions

Expert Solution

Code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student_t
{
  char first_name[20];
  char last_name[20];
  int id;
  float per;
  char grad[1];
};
struct student_t s[5];

struct student_t* getStudentInfo(){
  for(int i=0; i<5; i++)
 {
  printf("Enter %d student's first name : ",i+1);
  scanf("%s",s[i].first_name);
  printf("Enter %d student's last name : ",i+1);
  scanf("%s",s[i].last_name);
  printf("Enter %d student ID: ",i+1);
  scanf("%d",&s[i].id);
  printf("Enter %d student percentage: ",i+1);
  scanf("%f",&s[i].per);
 }
 return s;
}

void calStudentGrade(struct student_t* s){

 for(int i=0; i<5; i++)
 {
  if(s[i].per>=90)
    strcpy(s[i].grad,"A");
  else if(s[i].per>=80 && s[i].per<90)
    strcpy(s[i].grad,"B");
  else if(s[i].per>=70 && s[i].per<80)
    strcpy(s[i].grad,"C");
  else if(s[i].per>=60 && s[i].per<70)
    strcpy(s[i].grad,"D");
  else if(s[i].per>=60 && s[i].per<70)
    strcpy(s[i].grad,"E");
  else
    strcpy(s[i].grad,"F");
 }
}

void printStudentInfo(struct student_t* s){

  printf("NAME\t\t\tSID\t\t\tSCORE\t\tGRADE\n");
  for(int i = 0;i<5;i++)
  {
    printf("%s, %s\t%d\t\t\t%.2f\t\t%s\n",s[i].last_name,s[i].first_name,s[i].id,s[i].per,s[i].grad);
  }
}

int main()
{
 struct student_t* st = getStudentInfo();
 calStudentGrade(st);
 printStudentInfo(st);

  return 0;
}

(Feel free to throw an upvote or comment below if you have any doubts)


Related Solutions

Complete the following assignment in C programming language. Get the user’s first name and store it...
Complete the following assignment in C programming language. Get the user’s first name and store it to a char array Declare a character array to hold at least 20 characters. Ask for the user’s first name and store the name into your char array. Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces. Get 3 exam scores from the user: Declare an array of 3 integers Assume the scores are out...
c++ language for this assignment use real world example. Your application must be a unique project...
c++ language for this assignment use real world example. Your application must be a unique project and must incorporate the use of an STL container and/or iterator and at least 7 STL algorithms with an option to exit. Your application must contain at least 8 menu options. You will decide how to implement these menu selections.
#C language array must store at least 50 inputs Game Scores Assignment Outcomes: Demonstrate the ability...
#C language array must store at least 50 inputs Game Scores Assignment Outcomes: Demonstrate the ability to create a menu driven program. Demonstrate the ability to create and use a 2D array on the stack. Demonstrate the use of functions. Demonstrate good programming style. Program Specifications: Your program will read in "game scores" from the user. Each score consists of a score for YOUR team and a score for the OTHER team. You don't need names or dates for the...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. The first task is to find the prime factorization of a number. Prime number is a natural number greater than 1 that is not a product of two smaller...
Tom wants to start a new project. A project requires a start up cost of $11000...
Tom wants to start a new project. A project requires a start up cost of $11000 today and 20 annual cost of $4500 starting in one year. Starting at the end of the 21th year, the project returns 10 annual payments of $Y. Find Y so that the project yields an annual effective rate of 5% over the 30 years. PLZ by hand and not excel
In C language Assignment Extend the Game of Life assignment to load its configuration from a...
In C language Assignment Extend the Game of Life assignment to load its configuration from a file. Functional Requirements MUST load the initial state from text file MUST load the number of rounds to play from text file COULD load the grid size from the file Nonfunctional Requirements MUST compile without warnings and error Source code: life.h /* * life.h * *  Created on: Sep 20, 2020 *      Author: Joker Zhong */ #ifndef LIFE_H_ #define LIFE_H_ #define XSIZE   15 #define YSIZE   15 #define DEFAULTROUNDS...
CS 400 Assignment 5 Recursive/Backtracking: Generating Permutations WRITE CODE IN C++ PROGRAMMING LANGUAGE WITH COMMENTS INCLUDED...
CS 400 Assignment 5 Recursive/Backtracking: Generating Permutations WRITE CODE IN C++ PROGRAMMING LANGUAGE WITH COMMENTS INCLUDED Description: Mimic the code for N-queen problem (https://introcs.cs.princeton.edu/java/23recursion/Queens.java.html), develop a program that generates all permutations for the set {1, 2, 3, 4, 5}. The output should contain all 5! = 120 permutations. Output Sample: P#1: 1 2 3 4 5 P#2: 1 2 3 5 4 P#3: 1 2 4 3 5 ... P#120: 5 4 3 2 1 Hint: - Thoroughly study the...
Managers of CVS Pharmacy are considering a new project. This project would be a new store...
Managers of CVS Pharmacy are considering a new project. This project would be a new store in Odessa, Texas. They estimate the following expected net cash flows if the project is adopted. Year 0: ($1,250,000) Year 1: $200,000 Year 2: $500,000 Year 3: $400,000 Year 4: $300,000 Year 5: $200,000 Suppose that the appropriate discount rate for this project is 7.7%, compounded annually. Calculate the net present value for this proposed project. Do not round at intermediate steps in your...
Managers of CVS Pharmacy are considering a new project. This project would be a new store...
Managers of CVS Pharmacy are considering a new project. This project would be a new store in Odessa, Texas. They estimate the following expected net cash flows if the project is adopted. Year 0: ($1,250,000) Year 1: $200,000 Year 2: $500,000 Year 3: $400,000 Year 4: $300,000 Year 5: $200,000 Suppose that the appropriate discount rate for this project is 5.2%, compounded annually. Calculate the net present value for this proposed project. Do not round at intermediate steps in your...
Assignment (C language) We will simulate the status of 8 LEDs that are connected to a...
Assignment (C language) We will simulate the status of 8 LEDs that are connected to a microcontroller. Assume that the state of each LED (ON or OFF) is determined by each of the bits (1 or 0) in an 8-bit register (high-speed memory). Declare a char variable called led_reg and initialize it to 0. Assume that the least-significant bit (lsb) controls LED#0 and the most-significant bit (msb) controls LED#7. In the main function, build and present a menu to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT