On a previous question:
"Write a C code that creates an honor list for the top six students at SMC. Your
I received the below code, but I received errors when ran. Attached is a screenshot of the errors.
Is there something I should change?
#include <stdio.h>
#include <string.h>
int main()
{
int i,n=10,a,j;
char NAME[n][30],MAJOR[n][30],str[10];
float GPA[n];
//execute for loop from 0 to number of top student
for(i=0; i<n; i++)
{
//input student NAME
printf("Enter student NAME:");
scanf("%d",&a);
scanf("%[^\n]%*c",NAME[i]);
//input MAJOR name
printf("Enter MAJOR:");
scanf("%[^\n]%*c",MAJOR[i]);
//take GPA from user
printf("Enter GPA:");
scanf("%f",&GPA[i]);
}
//sort data in descending order based on GPA
//so first 6 student are top 6 students
for(i=0; i<n-1; i++)
{
for(j=0; j<n-i-1; j++)
{
//if you want to sort data in ascending order then use GPA[j]>GPA[j+1]
if(GPA[j]<GPA[j+1])
{
//swap GPA
float tmp=GPA[j];
GPA[j]=GPA[j+1];
GPA[j+1]=tmp;
//swap NAME
char s[30];
strcpy(s,NAME[j]);
strcpy(NAME[j],NAME[j+1]);
strcpy(NAME[j+1],s);
//swap MAJOR
char s1[30];
strcpy(s1,MAJOR[j]);
strcpy(MAJOR[j],MAJOR[j+1]);
strcpy(MAJOR[j+1],s1);
}
}
}
char sNAME[30]="Name";
char sMAJOR[20]="Major";
char sGPA[10]="GPA";
//print formated output after sorting
printf("\n%-30s %20s %10s\n",sNAME,sMAJOR,sGPA);
for(i=0; i<n; i++)
{
printf("%-30s %20s %10.2f\n",NAME[i],MAJOR[i],GPA[i]);
}
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 6 images
- Write a C++ program that prompts the user for 3 values: the half life of an element, the starting quantity, and the target remaining quantity. For the purposes of this program, don't worry about the units of these values. Print out a table with 3 columns: time elapsed, quantity remaining, and percentage of original quantity remaining. Starting when time elapsed = 0, print rows at every half life until the quantity remaining is equal to or less than the target remaining quantity. Finally, print out a message to let the user know how much time needs to elapse to reach the target remaining quantity. All numbers should be printed with at most 2 places after the decimal pointarrow_forwardin C++: Given a decimal number, your code must convert the decimal number into binary, and insert the three necessary check bits that validate it as being correctly assembled and received. Please display the following results: -1 The Original Decimal Number -2 The Correct Form of the resulting Hamming Code 1: 15 2: 7 3: 12 4: 2 5: 6arrow_forwardYou are tasked with writing a program to process students’ end of semester marks. For each student you must enter into your program the student’s id number (an integer), followed by their mark (an integer out of 100) in 4 courses. A student number of 0 indicates the end of the data. A student moves on to the next semester if the average of their 4 courses is at least 60 (greater than or equal to 60). Write a program to read the data and print, for each student: The student number, the marks obtained in each course, final mark of the student (average of all the marks), their final grade (A,B,C,D or F) and whether or not they move on to the next semester. In addition, after all data entry is completed, print The number of students who move on to the next semester and the number who do not. The student with the highest final mark (ignore the possibility of a tie). Grades are calculated as follows: A = 70 and over, B = 60 (inclusive) -70, C = 50(inclusive)-60 D =…arrow_forward
- C++ Language 2arrow_forwardGiven that RAM (Random Access Memory) is a storage medium that is subject to degradation over time, is it even possible for it to fulfill all of our requirements?arrow_forwardGiven: int num1, num2, newNum;double x, y;Which of the following assignments are valid? If an assignment is not valid,state the reason.a. num1 = 35;b. newNum = num1 – num2;c. num1 = 5; num2 = 2 + num1; num1 = num2 / 3;d. num1 * num2 = newNum;e. x = 12 * num1 - 15.3;f. num1 * 2 = newNum + num2;g. x / y = x * y;h. num2 = num1 % 2.0;i. newNum = static_cast<int> (x) % 5;j. x = x + y - 5;k. newNum = num1 + static_cast<int> (4.6 / 2);arrow_forward
- C++ Here is the original question for what it is worth. Please do not give me an answer you found on Chegg. I have one of those accounts too. Please read carefully, I have submitted this question several times and no one could follow directtions. I have my code doing what is asked of the problem with the exception of displaying the last_name, first_name A teacher is requiring her students to line up in alphabetical order, according to their first names..For example, in one class Chapel, Christine would be at the front and Uhura, Nyota would be last. The program will get the names from a file using getline since the file name includes spaces. The names should be read in until there is no more data to read. The program should prompt the user for the file name and read the data from the file. Note that these names might include spaces; handle your input accordingly. The expected output is two names; do not show the entire file. Do not use arrays or sorting for this problem. Here is my…arrow_forwardIn Python Assume that you have a data structure of the following: A list of hockey players. Each hockey player is a list that includes their Rank (int), Name (String), Team (String), Age (int), Goals (int), Assists (int), Points (int) in that order. Write a function called most_goals that takes in the list of hockey players and returns the name of the player with the most goals. For example: Test Result print(most_goals(nhl_list1)) David Pastrnakarrow_forwardQuestion: In C#, how can I recreate this into a Windows form Application instead of a console application? Please show a photo of the display and show the code that you used, thank you! Problem: Write a function Seperate( number ) that separates an integer number (ranging from 0 to 99999) into its digits. For example, if the number is 42329, the function finds 4, 2, 3, 2, 9. If the number is 323, the function finds 0, 0, 3, 2, 3. (Hint: use modulus and integer division operations.) Code: using System;public class RecExercise4{static void Main(){Console.Write("Input any number (ranging from 0 to 99999) : ");int num = Convert.ToInt32(Console.ReadLine());Console.Write(" The digits in the number are : ");separateDigits(num);} static void separateDigits(int n){int i = 4;int[] arr;arr = new int[5];while (i>-1){arr[i] = n%10;n = n/10;i--;}foreach(int j in arr)Console.Write(" " + j);}}arrow_forward
- create a passphrase generator on c++ that follows this. Please make sure the code works on c++ visual studios Diceware™ is a method for picking passphrases that uses ordinary dice to select words at random from a special list called the Diceware Word List. Each word in the list is preceded by a five digit number. All the digits are between one and six, allowing you to use the outcomes of five dice rolls to select a word from the list. Here is a short excerpt from the English Diceware word list: 16655 clause 16656 claw 16661 clay 16662 clean 16663 clear 16664 cleat 16665 cleft 16666 clerk 21111 cliche 21112 click 21113 cliff 21114 climb 21115 clime 21116 cling 21121 clink 21122 clint 21123 clio 21124 clip 21125 clive 21126 cloak 21131 clock The complete list contains 7776 short words, abbreviations and easy-to-remember character strings. The average length of each word is about 4.2 characters. The biggest words are six characters long. The English list is based on a longer word list…arrow_forwardWithout using any string literal notation, how do you create the C++ statement that manually creates a null-terminated C-style string as an array of characters. Use the string “Sampson” as your example. Which element is stored in the base address of the array?arrow_forwardI'm trying to create a c program that will take in a ten-digit ISBN number and then check to see if the number is valid by calculating its weighted sum. This is the code that I have up to know, but I'm not sure what to do next. Can you give me some pointers? DOCUMENTATION-------------This program will determine if an ISBN number is valid by calculating its weighted sum.********************************************************************/#include <stdio.h>#include <stdbool.h> #define ISBN_SIZE 10#define MOD_NUM 11 void printInstructions(void);void getIsbn(int isbnArray[]);void printIsbn(int isbnArray[]);int calculateWeightedSum(int isbnArray[]);bool isIsbnValid(weightedSum);void printGoodbye(void); int main(){int isbnArray[ISBN_SIZE] = {0}; printInstructions();getIsbn(isbnArray); printf("\n\nThe ISBN ");printIsbn(isbnArray); if(isIsbnValid(calculateWeightedSum(isbnArray))){printf(" is valid.");}else{printf(" is not valid.");} printGoodbye(); return 0;}…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education