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 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...
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...
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
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...
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
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...
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing...
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing b) dangling reference
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT