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...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
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...
C++ programming Complete the code to input and store all the information in the structure Book:...
C++ programming Complete the code to input and store all the information in the structure Book: title, author, year and pages. Complete the function print() with arguments and code to print a Book variable in the following format: Book title: <title> Book author: <name> Published in <year> Number of pages: <pages> #include <iostream> using namespace std; struct Book { string title; string author; string year; int pages; }; void print(/*arguments*/) { //Complete function } int main() { //Declare structure variable...
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...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT