Question

In: Computer Science

C# in Visual Studio Practice Concepts ● Practice using conditional logic and expressions ● Practice protecting...

C# in Visual Studio

Practice Concepts

● Practice using conditional logic and expressions

● Practice protecting numeric input prompts (Int.TryParse(Console.ReadLine(), out);

Problem Description

create a Console Application using the .NET Framework. C#

This project will implement a short 3-question quiz.

Create a quiz application that has 3 questions. At least one of the questions must offer multiple choices,

and at least one question must prompt the user to enter a numeric input. The third question can be

either multiple choice or numeric input.

Scoring a multiple choice question will work as follows:

● If the user enters the correct choice value, award 3 points.

● If the user enters a valid offered choice, but the incorrect answer, award 1 point.

● If the user enters an invalid option, award 0 points.

Scoring a numeric input question will work as follows:

● If the user enters the correct numeric value, award 3 points.

● If the user enters a valid number, but the incorrect answer, award 1 point.

● If the user enters a non-numeric value, award 0 points.

Final scoring:

● If the user answered all three questions correctly, award 1 bonus point, for a maximum of 10

points earned. (3 points for each correct answer, plus the bonus point).

Test Conditions

● Your program should be free of syntax errors and build and compile properly.

● Due to the numerous ways you can answer these questions, make sure to test your program

over multiple conditions. Test the case where all answers are correct, all answers are incorrect,

etc.

● Note: On this quiz, it should be possible to score: 0 points, 1 point, 2 points, 3 points, 4 points,

5 points, 6 points, 7 points, and 10 points. Can you test each case?

Solutions

Expert Solution


/*C # program that prompts the user to enter choice for multiple-choice question,  one numeric question and then multiple-choice question. If all three questions are correct, then award 10 points. Otherwise set points as per the given instructions.*/
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QuizTest
{
class Program
{
static void Main(string[] args)
{

//declaration of variables
int choice;
int userInputValue;
int CORRECT_ANSWER = 3;
int WRONG_ANSWER = 1;
int INVALID=0;
int BONUS_POINT = 1;
bool all_correct = true;
int points=0;


//Question1: Multiple choice
Console.WriteLine ("1.What is value of earth gravitational constant ?");
Console.WriteLine("1){0,-20}2){1,-20}3){2,-20}4){3,-20}", "9.807 m/s²", "10.807 m/s²", "11.807 m/s²", "12.807 m/s²");
Console.WriteLine("Answer : ");
if (int.TryParse(Console.ReadLine(), out choice))
{
if (choice == 1)
points = points + CORRECT_ANSWER;
else if (choice == 2 || choice == 3 || choice == 4)
{
all_correct = false;
points = points + WRONG_ANSWER;
}
}
else
{
all_correct = false;
points = points + INVALID;
}

//Question2: Numeric type
Console.WriteLine("\n2.What is size of /'char/' in C # programming?");
Console.Write("Answer : ");
if (int.TryParse(Console.ReadLine(), out userInputValue))
{
//check if user entered correct answr
if (userInputValue == 2)
//Add 3 points
points = points + CORRECT_ANSWER;
else if (userInputValue < 0)
{
//Add 1 points
points = points + WRONG_ANSWER;
all_correct = false;
}
}
else
{
all_correct = false;
points = points + INVALID;
}


//Question3: Multiple choice
Console.WriteLine("\n\n3.What is size of integer in c# programming ?");
Console.WriteLine("1){0,-20} 2){1,-20} 3){2,-20} 4){3,-20}", "2 Bytes", "4 Bytes", "6 Bytes", "8 Bytes");
Console.WriteLine("Answer : ");
//Check if user choice is valid
if (int.TryParse(Console.ReadLine(), out choice))
{
//check if user entered correct answr
if (choice == 2)
//Add 3 points
points = points + CORRECT_ANSWER;
//valid choice but incorrect answer
else if (choice ==1 || choice == 3 || choice == 4)
{
//set boolean to false
all_correct = false;
//Add 1 points
points = points + WRONG_ANSWER;
}
}
else
{
all_correct = false;
points = points + INVALID;
}

if(all_correct)
Console.WriteLine("\nTotal points scored : {0} ", points+BONUS_POINT );
else
Console.WriteLine("\nTotal points scored : {0} ", points);

Console.ReadKey();

}
}
}
------------------------------------------------------------------------------------------------------------------------

Sample Output:


Related Solutions

ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
answer the following using C# Design and program a Visual Studio Console project in C# that...
answer the following using C# Design and program a Visual Studio Console project in C# that allows your user to enter a number. The program will examine the number to see if it is prime. If it is prime, it will print the next higher prime and the next lower primes to the console. If the number entered by the user is not prime, display a message to that effect. All code should be written by you. Do not copy/paste...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page to access a database and display the data from a table by providing an SQL statement. Create the page with these requirements:     create label, textbox and button     the textbox will capture the SQL statement     the button will process the statement and display the results 2. Add necessary data access pages to your project. 3. Display the data in Gridview
Need it in C# using visual studio (also can you show me how to implement the...
Need it in C# using visual studio (also can you show me how to implement the code in vs) Create a New Project named Preferred Customer to be used in a retail store for preferred customers, where customers can earn discount on all purchases depending upon how much money they are going to spend. To begin with designing your Application, you must add a class named Person with properties for holding a Person’s Name, Address and Telephone Number. Next step...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT