if answer all i will give a thumbs up odule 11: Exam 2 -Requires Respondus LockD
ID: 3707105 • Letter: I
Question
if answer all i will give a thumbs up odule 11: Exam 2 -Requires Respondus LockDown Browser+Webcam ted: Apr 13 at 2:57pm uiz Instructions 80 minute exam Exam may NOT be stopped and restarted Try to answer all questions partial credit will be given when You can assume the following libraries and functions are available for all questions on the exam necessary e Bincludesstdio.h> printf and scanf includesctype.hs tolower and toupper You do not need to write a complete program unless the question asks for a complete program read each question carefully D Question 5 5 pts Write a function definition called GameSurvey that takes one character argument/parameter called called pricePtr. The function has a void return type. When the variable argument gameS contalins the character x or X. print the word XBox and store 299.99 in the "value at" pricePtr When gameS contains the character p or P print the word Playstation and store a 4 t gameS and one pointer to a double 99.99 When gameS contains anything else, store a 0.0 ??.?.IE????x'x,EE MacBook Ar 30 0Explanation / Answer
============================================================================
#include <stdio.h>
#include <stdlib.h>
// GameSurvey function :Q5
void GameSurvey (char gameS, double* pricePtr) {
if (gameS == 'x' || gameS == 'X'){
printf(" Xbox");
*pricePtr = 299.99;
}
else if (gameS == 'p' || gameS == 'P'){
printf(" Playstation");
*pricePtr = 499.99;
}
else {
*pricePtr = 0.0;
}
}
// Loop for sum of all integers given by user : Q6
void SumOfIntegers() {
int nums[45]; // Number array
int counter = 0; // for counting
int sumTotal = 0; // for storing sum of integers
// Read input from user
for (counter = 0; counter < 45; counter++) {
printf(" Enter Integer %d : ", counter+1);
scanf("%d",&nums[counter]); //Stores the input to array
sumTotal = sumTotal + nums[counter]; //Calculates the sum of integers
}
//Print the array
printf(" The Integer array is: ");
for (counter = 0; counter < 45; counter++)
{
printf("%d ", nums[counter]); // Print the array Element
}
printf(" Sum of Integers: %d", sumTotal); // Print sum.
}
// Question No. 7
void DisplayLargeNumbers(double numList[], int count, double large) {
int counter = 0; //for counting
printf(" The numbers larger than or equal to %g are: ",large); //%g to avoid zeros afte decimal
// we run the counter till we reach "count" number of elements
for(counter = 0; counter < count; counter++){
if(numList[counter] >= large) { //If any nmber is larger than 'large'
//Print that larger number
printf(" %g ", numList[counter]); // %g used to for not to print trailing zeroes.
}
}
}
// Main program to test our functions
int main(void) {
double price;
double numList[] = {23.4, 56.8, 12.0, 33.67, 80, 76.12345678, -23};
// Testing Question No. 5
GameSurvey('x',&price);
printf(" Price: %.2lf", price); //%.2 for 2 digits after decimal point
GameSurvey('P',&price);
printf(" Price: %.2lf", price);
// Testing Sum of Integers. Question Number 6
SumOfIntegers();
// Testing Question Number 7
DisplayLargeNumbers(numList, 7, 23.4);
//puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
Main Program for Q8 and functions specified in question.
============================================================================
#include <stdio.h>
void GetAmount(double *amountPtr) {
printf(" Enter double number: ");
//getamount will have the address, which needs to be passed to scanf
scanf("%lf",amountPtr);
}
void AddOrSubtract(double amount, double* totalPtr) {
int option;
printf(" What do you want to do? Add[1] or Subtract[2]: ");
printf(" Please Enter the option: (1 or 2): ");
scanf("%d",&option); // read option
if(option == 1) { // Selected Add
*totalPtr = *totalPtr + amount; //Add amount to totalPtr value
}
else if (option == 2) { // Selected Subtract
*totalPtr = *totalPtr - amount; //Subtract the amount.
}
else { //Entered option other than 1 and 2
printf(" Not Recognized");
}
}
int main() {
double amount; // To read the amount by GetAmount function
double total=0; // To calculate Total
//Passing amount by reference. So that we can pass it to the AddorSubtract
GetAmount(&amount);
// We are passing the amount returned by the GetAmount function and reference to total
AddOrSubtract(amount, &total);
printf(" Total Calculated: %g", total); //Prints the total.
// Running once more to check the total.
GetAmount(&amount);
AddOrSubtract(amount, &total);
printf(" Total Calculated (2nd Run): %g", total); //Prints the total.
return 0;
}
Programs Output: Program 1 : Q5,6,7
Xbox
Price: 299.99
Playstation
Price: 499.99
Enter Integer 1 : 1
Enter Integer 2 : 2
Enter Integer 3 : 3
Enter Integer 4 : 4
Enter Integer 5 : 5
Enter Integer 6 : 6
Enter Integer 7 : 7
Enter Integer 8 : 8
Enter Integer 9 : 9
Enter Integer 10 : 10
Enter Integer 11 : 1
Enter Integer 12 : 2
Enter Integer 13 : 3
Enter Integer 14 : 4
Enter Integer 15 : 5
Enter Integer 16 : 6
Enter Integer 17 : 7
Enter Integer 18 : 8
Enter Integer 19 : 9
Enter Integer 20 : 10
Enter Integer 21 : 1
Enter Integer 22 : 2
Enter Integer 23 : 3
Enter Integer 24 : 4
Enter Integer 25 : 5
Enter Integer 26 : 6
Enter Integer 27 : 7
Enter Integer 28 : 8
Enter Integer 29 : 9
Enter Integer 30 : 10
Enter Integer 31 : 1
Enter Integer 32 : 2
Enter Integer 33 : 3
Enter Integer 34 : 4
Enter Integer 35 : 5
Enter Integer 36 : 6
Enter Integer 37 : 7
Enter Integer 38 : 8
Enter Integer 39 : 9
Enter Integer 40 : 10
Enter Integer 41 : 1
Enter Integer 42 : 2
Enter Integer 43 : 3
Enter Integer 44 : 4
Enter Integer 45 : 5
The Integer array is:
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5
Sum of Integers: 235
The numbers larger than or equal to 23.4 are: 23.4 56.8 33.67 80 76.1235
Program Output for Q8 (2nd Program)
C:prog>gcc main.c
C:prog>a.exe
Enter double number: 2.5
What do you want to do? Add[1] or Subtract[2]:
Please Enter the option: (1 or 2): 1
Total Calculated: 2.5
Enter double number: 3.5
What do you want to do? Add[1] or Subtract[2]:
Please Enter the option: (1 or 2): 1
Total Calculated (2nd Run): 6
C:prog>a.exe
Enter double number: 1.5
What do you want to do? Add[1] or Subtract[2]:
Please Enter the option: (1 or 2): 1
Total Calculated: 1.5
Enter double number: 1.5
What do you want to do? Add[1] or Subtract[2]:
Please Enter the option: (1 or 2): 2
Total Calculated (2nd Run): 0
C:prog>a.exe
Enter double number: 5
What do you want to do? Add[1] or Subtract[2]:
Please Enter the option: (1 or 2): 5
Not Recognized
Total Calculated: 0
Enter double number: 1
What do you want to do? Add[1] or Subtract[2]:
Please Enter the option: (1 or 2): 2
Total Calculated (2nd Run): -1
C:prog>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.