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

Write a c statement to declare variables of primitive data types, and assign values to the...
Write a c statement to declare variables of primitive data types, and assign values to the variables. Use common control structure in c, such as if, switch, break, for, while statements. Write a c program that takes command line parameters, and perform some computation based on the command line input. Write c statements to generate random number within a certain range. Write a c statement to declare array variables of primitive data types, and assign values to the elements of...
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);
Unix Create a script that will declare an array and assign four values from the command...
Unix Create a script that will declare an array and assign four values from the command line. 1. Use these four values - Paul, Ringo, George, John, - in that order 2. Display the content of the array, displaying the values in this format and this order The first array value is "John" The second array value is "Paul" The third array value is "George" The fourth array value is "Ringo"
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.
1. What is the structure data type in C? 2. What is the value ranges of...
1. What is the structure data type in C? 2. What is the value ranges of data type of unsigned char, unsigned short, respectively? 3. How many regular resisters are in this X-CPU? 4. How does the X-CPU access the memory? 5. What is the maximum memory address? 6. Which statements in the code is to increase the PC value? 7. What is the minimal cycle number that is just needed to print “Hello world!” 4 times? 8. what is...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT