Question

In: Computer Science

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.

  1. 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.
  2. Get 3 exam scores from the user:
    • Declare an array of 3 integers
    • Assume the scores are out of 100, and use a for loop to get user’s input
    • Your prompts should print out which exam score you are asking for:
      1. Example: “What is the score of Exam #1?” … “What is the score of Exam #3?”
    • Warning: Be careful of your array indexes!
  3. Find out the average exam score:
    • Use a for loop to calculate the sum of all exams.
    • Divide the sum by 3 to get the average and store the is data in a variable.
  4. Print out the summary for the use similar to:
    • “Hello NAME, based on your exam score of 80, 90, and 100, your average is 90.0 with a letter of an ‘A.’”

Solutions

Expert Solution

/* Program written in C Programming language using DEV-C++ Editor on windows operating system */

#include<stdio.h>
int main(){
   char fname[10];//firstname array
   char lname[10];//lname array
   printf("\n Enter First name and Last name of Student:::");
   //accept two string from user using scanf statement
   scanf("%s%s",&fname,&lname);
   int score[3];//score array with three size
   int tempscore;//temp variable to hold score
   int i=0;//index for getting three score
   for(i=0;i<3;i++){
       int f=1;
       // while is true till user enter valid score
       while(f){
           //accept score
       printf("\n Enter Valid Score for Examp %d ",(i+1));
       scanf("%d",&tempscore);
       // check validity of score
       if(tempscore>=0 && tempscore<=100){
           score[i]=tempscore;
           f=0;
       }
       }// end of while
      
   }//end of for loop
   int ch;
   int choice,sum=0;
   float average;
   do{
       //accept choice from user
       printf("\n 1. What is the score of Exam #1? Enter 1");
       printf("\n 2. What is the score of Exam #2? Enter 2");
       printf("\n 3. What is the score of Exam #3? Enter 3");
       printf("\n 4. Get Average Score of student");
       printf("\n 5. Get Summary of All tests/Student");
       printf("\n");
       scanf("%d",&choice);
       switch(choice){// jump to the case
           case 1:printf("\n Score of Test 1 is %d ",score[0]);// print score of test 1
           break;
           case 2:printf("\n Score of Test 2 is %d ",score[1]);// print score of test 2
           break;
           case 3:printf("\n Score of Test 3 is %d ",score[2]);// print score of test 3
           break;
           case 4:
               sum=0;
                for(i=0;i<3;i++)
               sum=sum+score[i]; // get sum sum of testes
               average=(float)sum/(float)3;//get average
               printf("\n Average score of all tests is %f ",average);
           break;
           case 5:
               sum=0;
                for(i=0;i<3;i++)
               sum=sum+score[i]; // get sum sum of testes
               average=(float)sum/(float)3;//get average
               printf("\n Average score of Test 1 =%d,Test 2=%d,Test 3=%d is %f ",score[0],score[1],score[2],average);
           break;
          
           default:printf("\n Wrong choice entered try again");
       }//end of switch
       printf("\n DO you want to continue then enter 1 for continue :");
       scanf("%d",&ch);
   }while(ch==1);
}

/*

output


Enter First name and Last name of Student:::Bhushan Mahajan

Enter Valid Score for Examp 1 965

Enter Valid Score for Examp 1 -698

Enter Valid Score for Examp 1 58

Enter Valid Score for Examp 2 47

Enter Valid Score for Examp 3 -1

Enter Valid Score for Examp 3 847

Enter Valid Score for Examp 3 10

1. What is the score of Exam #1? Enter 1
2. What is the score of Exam #2? Enter 2
3. What is the score of Exam #3? Enter 3
4. Get Average Score of student
5. Get Summary of All tests/Student
1

Score of Test 1 is 58
DO you want to continue then enter 1 for continue :1

1. What is the score of Exam #1? Enter 1
2. What is the score of Exam #2? Enter 2
3. What is the score of Exam #3? Enter 3
4. Get Average Score of student
5. Get Summary of All tests/Student
2

Score of Test 2 is 47
DO you want to continue then enter 1 for continue :1

1. What is the score of Exam #1? Enter 1
2. What is the score of Exam #2? Enter 2
3. What is the score of Exam #3? Enter 3
4. Get Average Score of student
5. Get Summary of All tests/Student
3

Score of Test 3 is 10
DO you want to continue then enter 1 for continue :1

1. What is the score of Exam #1? Enter 1
2. What is the score of Exam #2? Enter 2
3. What is the score of Exam #3? Enter 3
4. Get Average Score of student
5. Get Summary of All tests/Student
4

Average score of all tests is 38.333332
DO you want to continue then enter 1 for continue :1

1. What is the score of Exam #1? Enter 1
2. What is the score of Exam #2? Enter 2
3. What is the score of Exam #3? Enter 3
4. Get Average Score of student
5. Get Summary of All tests/Student
5

Average score of Test 1 =58,Test 2=47,Test 3=10 is 38.333332
DO you want to continue then enter 1 for continue :

*/


Related Solutions

Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio...
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio development environment 3. To practice on writing a C# program Task 1: Create documentation for the following program which includes the following: a. Software Requirement Specification (SRS) b. Use Case Task 2: Write a syntactically and semantically correct C# program that models telephones. Your program has to be a C# Console Application. You will not implement classes in this program other than the class...
Complete the following exercises using C programming language. Take screenshots of the code and its output...
Complete the following exercises using C programming language. Take screenshots of the code and its output where specified and paste them into in a well-labeled Word document for submission. Scenario Assume you are the CIO of an organization with three different IT department locations with separate costs. You want a program to perform simple IT expenditure calculations. Your IT expenditure target is $35,000 per site. Site expenditures: Site 1 – $35,000. Site 2 – $37,500. Site 3 – $42,500. Exercise...
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
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. Declare a structure called student_t that contains : First name Last name Student ID Number Percentage grade Letter grade 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...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string. The alphabet for generating DNA sequences is {A, T, G, C}. Write a regular expression that represents all DNA strings that begin with ‘A’ and end with ‘T’. Note: assume empty string is not a valid string. Design a deterministic finite automaton to recognize the regular expression. Write a program which...
C Programming Language: For this lab, you are going to create two programs. The first program...
C Programming Language: For this lab, you are going to create two programs. The first program (named AsciiToBinary) will read data from an ASCII file and save the data to a new file in a binary format. The second program (named BinaryToAscii) will read data from a binary file and save the data to a new file in ASCII format. Specifications: Both programs will obtain the filenames to be read and written from command line parameters. For example: - bash$...
The following is for C programming language: I want to scan for initials in a line...
The following is for C programming language: I want to scan for initials in a line of text. my line of text is as follows: 12345 3.5000 a j 12346 4.1000 s p The first number represents the student ID, the second number represents the gpa, the third character represents the first initial and the fourth character represents the last initial of the student. My text file contains these values. The following is my code: fscanf(fp, "%d %c %c", &studentID,...
The following question must be answered in the C programming language and may not be written...
The following question must be answered in the C programming language and may not be written in C++ or any other variation. Problem 5 This problem is designed to make sure you can write a program that swaps data passed into it such that the caller's data has been swapped. This is something that is done very frequently in manipulating Data Structures. The Solution / Test Requirements I want your program to demonstrate that you understand how to swap information...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT