Question

In: Computer Science

Create your own data type using a C++ structure. Assign values to a variable of that...

  • Create your own data type using a C++ structure.
  • Assign values to a variable of that data type.
  • Retrieve values from the variable of that data type.

Description:

In this lab you will choose the statements to create a program that:

Creates a brand new data type called "Monster". Once created, creates a variable of type Monster and assign values to the variable and then display the contents.

This lab will again take the form of a guided multiple-choice quiz like you had in the previous labs. For each question, pick the statement that implements the given requirement.

A Sample Run:

Monster name: Orc
Monster movement: 5
Monster dps: 3.5

Solutions

Expert Solution

//I have implemented the code you can take the input from the console and to run program use the // //below link from repl

//I have even used the strucure and used it as a data type

// LINK : https://repl.it/@FAYAZPASHA/OutstandingQuizzicalCarriers#main.cpp


#include<bits/stdc++.h>
using namespace std;

struct Monster{ //A User Defined Structure
   string name;
   int movement;
   float dps;
};

int main(){
   Monster monster;  //Using the predefined structure as a datatype

   //monster.name = "Orc";
   //monster.movement = 5;
   //monster.dps = 3.5;

   cout << "Enter Monster name: ";
   string name; cin >> name;

   cout << "Enter Monster Movements: ";
   int mov; cin >> mov;

   cout << "Enter Monster DPS: ";
   float dp; cin >> dp;

   monster.name = name;
   monster.movement = mov;
   monster.dps = dp;


   cout << "Monster name: " << monster.name << endl;
   cout << "Monster movement: " << monster.movement << endl;
   cout << "Monster dps: " << monster.dps << endl;

   return 0;
}


Related Solutions

Using C#: Create a Form that consists of a PictureBox and 3 radio buttons. Assign an...
Using C#: Create a Form that consists of a PictureBox and 3 radio buttons. Assign an image of your choice to the PictureBox. Each radio button should be associated with a specific PictureBox size mode. When the user clicks on a specific radio button, the PictureBox's size mode should be changed to reflect the selection.
define "hypothesis" and create your own using variable weight and eating habits. Be sure to clarify...
define "hypothesis" and create your own using variable weight and eating habits. Be sure to clarify which variable is independent and which us dependent in your explenation
(C++ ONLY) You will define your own data type. It will be a struct called Fraction....
(C++ ONLY) You will define your own data type. It will be a struct called Fraction. The struct will have 2 integer fields: numerator and denominator. You will write a function called reduce that takes a Fraction as a parameter and returns that Fraction in its reduced form. For example, if the fraction 2/4 is passed to the function, the fraction 1/2 will be returned. Consider any fraction with a denominator of 1 to be in reduced form. You will...
In C, create a program that displays the minimum and maximum values stored in a data...
In C, create a program that displays the minimum and maximum values stored in a data file "datafile.txt". Use the following function prototype:  void minmaxarray(float value, float *min, float *max);
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable...
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable (like ptr) which points to this array. Use this pointer variable to initialize the myNums array from 2 to 200 and then display the array elements. Delete the dynamic array myNums at the end. You just need to write part of the program.
In C Programing Create a stack using an array. Define the index variable of the array...
In C Programing Create a stack using an array. Define the index variable of the array name to be stacktop. Initially set stacktop to -1. Next create two functions push and pop. Both take as input 3 items: a pointer to the stack in memory, stacktop, and maxstack. Make sure to inc stacktop by one and also remember that stacktop[0] is the bottom of the stack and by stack rule cannot be accessed until all the other items are popped....
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
in C++ You will overload a function named printArray. The function will assign values to each...
in C++ You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. (6 points) Using the player switch portion of the tic tac toe game, create a function that does the switch. This is a practice in applying local variables, parameters, and global variables. (4 points)
C Assign Barbecue's data member caloriesInSlice with a value read from input. Then, assign Ham and...
C Assign Barbecue's data member caloriesInSlice with a value read from input. Then, assign Ham and Cheese's data member caloriesInSlice with another value read from input. Input will contain two integer numbers. #include <stdio.h> #include <string.h> typedef struct Pizza_struct { char pizzaName[75]; int caloriesPerSlice; } Pizza; int main(void) { Pizza pizzasList[2]; strcpy(pizzasList[0].pizzaName, "Barbecue"); strcpy(pizzasList[1].pizzaName, "Ham and Cheese"); /* Your code goes here */ printf("A %s slice contains %d calories.\n", pizzasList[0].pizzaName, pizzasList[0].caloriesPerSlice); printf("A %s slice contains %d calories.\n", pizzasList[1].pizzaName, pizzasList[1].caloriesPerSlice); return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT