Assume the following structure declaration exists for quest ions 10.18 through 10.20:
struct Rectangle
{
int length;
int width;
};
10.19 Assume the pointer you defined in question 10.18 points to a valid Rectangle structure. Write the statement that displays the structure’s members through the pointer.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Starting Out with C++: Early Objects
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Degarmo's Materials And Processes In Manufacturing
- Question 2 You are about to create a simple 2D shooting game. i) Create appropriate structures with the following information: Bullet isAvailable: bool Gun type: The gun type (e.g. Rifles or Pistol) bulletSize: Total bullets in the gun (e.g. 6 bullets in Pistol) bullets: An array of Bullet type. Maximum 100 bullets applied in the game. ii) Assume you have defined a variable called myWeapon as follows: Gun myWeapon; myWeapon.model "Machine Gun"; myWeapon.size 80; Write a code fragment to reload all the gun bullets status to true. iii) Create a function called shot that takes in a reference parameter as Gun type. The function displays the message "Reload" if the first bullet is empty. Otherwise, for every single bullet, it displays "Bang" and set the last bullet to false.arrow_forwardDrink Machine Simulator Write a program that simulates a soft drink machine. The program should use a structure that stores the following data: Drink Name Drink Cost Number of Drinks in Machine The program should create an array of five structures. The elements should be initialized with the following data: Drink Name Cost Number in Machine Cola .75 20 Root Beer .75 20 Lemon-Lime .75 20 Grape Soda .80 20 Cream Soda .80 20 Each time the program runs, it should enter a loop that performs the following steps: A list of drinks is displayed on the screen. The user should be allowed to either quit the program or pick a drink. If the user selects a drink, he or she will next enter the amount of money that is to be inserted into the drink machine. The program should display the amount of change that would be returned, and subtract one from the number of that drink left in the machine. If the user selects a drink that has sold out, a message…arrow_forwardIn c++ Create a structure named student with two attributes, name and copa. Define structure variables s1, in the main block(local to main menthod), s2(global), two structure variable as an array. Scan over all four structure variables and display. For example: Test Input Result 1 218CES001 7.1 215001 7.1 218CE500) 7.3 2105004 21BCES003 7.3 218CES004 7.4 7.4 218CE5002 21BC5002 7.2 7.2arrow_forward
- Activity 1 This program firstly initializes an object of struct Cirele with values and then updates those using pointers. The program uses structure notation once and pointer notation another afterwards. #include #include #define MIN 1 #define MAX 30 struct Circle { float xCoord; float yCoord; float radius; }; /* prototypes */ float getRandomNumber (int min, int max); void printByValue(struct Circle cirobj); void setValue(float *target, float newValue); void printByReference(struct Circle *cirObj); int main(void) { /* Declare a struct circle and name it circleobject */ struct Circle circleObject; /* Fill circleObject's members with random numbers */ circleobject.xCoord = getRandomNumber(MIN, MAX); circleobject.yCoord = getRandomNumber (MIN, MAX); circleobject.radius = getRandomNumber (MIN, MAX); /* Printing values of the circle by calling function print by value */ printByValue(circleobject); /* update values of circle one by one */ setValue (&circleobject.xCoord, getRandomNumber(MIN,…arrow_forward#ifndef lab5ExF_h #define lab5ExF_h typedef struct point { char label[10]; double x ; // x coordinate for point in a Cartesian coordinate system double y; // y coordinate for point in a Cartesian coordinate system double z; // z coordinate for point in a Cartesian coordinate system }Point; void reverse (Point *a, int n); /* REQUIRES: Elements a[0] ... a[n-2], a[n-1] exists. * PROMISES: places the existing Point objects in array a, in reverse order. * The new a[0] value is the old a[n-1] value, the new a[1] is the * old a[n-2], etc. */ int search(const Point* struct_array, const char* target, int n); /* REQUIRES: Elements struct-array[0] ... struct_array[n-2], struct_array[n-1] * exists. target points to string to be searched for. * PROMISES: returns the index of the element in the array that contains an * instance of point with a matching label. Otherwise, if there is * no point in the array that its label matches the target-label, * it should return -1. * If there are more than…arrow_forwardDeclare the following structure in a program, along with two instances (s1 and s2) as indicated: struct my_struct { int a; float b; } s1, s2; In the program declare a pointer to the structure. Ask the user to enter the values for each structure. Then, using the pointer, print the values of each structure s1 and s2. Don’t access the structure variables directly.arrow_forward
- Suppose that structures and variable p are declared as follows: struct new_struct{ char a; int b[10]; }; struct new_struct s; Which one of the following statements will update the 3rd element of b in the structure s to 34? s.b= 34; s.b[2] =34;arrow_forwardASSIGNMENT: Student Data Write a program that uses two structures Name and Student to store the following information for multiple students: 1. Create a NAME structure that consists of • First Name, • Middle Initial, and • Last Name. 2. Create a STUDENT structure that contains student information (Include the NAME structure within the Student information structure) o Name o ID o email • SSN • Program (an enum type containing programs such as CSCI, DBMS, INFM, SDEV)arrow_forward/* Movie List Example --Showing how to use vectors and structures */ #include <iostream> #include <iomanip> #include <string> #include <vector> using namespace std; // define a struct for a Movie object struct Movie // It is common for the struct name to be capitalized { string title = ""; // First member of structure - and initialized int year = 0; // Second member of structure - and initialized }; int main() { cout << "The Movie List program\n\n" << "Enter a movie...\n\n"; // get vector of Movie objects vector<Movie> movie_list; char another = 'y'; while (tolower(another) == 'y') { Movie movie; // make temporary new (initialized) Movie object cout << "Title: "; getline(cin, movie.title); cout << "Year: "; cin >> movie.year; movie_list.push_back(movie);…arrow_forward
- /* Movie List Example --Showing how to use vectors and structures */ #include <iostream> #include <iomanip> #include <string> #include <vector> using namespace std; // define a struct for a Movie object struct Movie // It is common for the struct name to be capitalized { string title = ""; // First member of structure - and initialized int year = 0; // Second member of structure - and initialized }; int main() { cout << "The Movie List program\n\n" << "Enter a movie...\n\n"; // get vector of Movie objects vector<Movie> movie_list; char another = 'y'; while (tolower(another) == 'y') { Movie movie; // make temporary new (initialized) Movie object cout << "Title: "; getline(cin, movie.title); cout << "Year: "; cin >> movie.year; movie_list.push_back(movie);…arrow_forwardIn C languagearrow_forwardClass and Data members: Create a class called Student that stores a student’s grades (integers) in a vector (do not use an array). The class should have data members that store a student’s name and course for which the grades are earned. Constructor(s): The class should have a 2-argument constructor that receives the student’s name and course as parameters and sets the appropriate data members to these values. Member Functions: The class should have functions as follows: Member functions to set and get the student’s name and course variables. A member function that adds a single grade to the vector. Only positive grades are allowed. Call this function AddGrade. A member function to sort the vector in ascending order. A member function to compute the average (x̄) of the grades in the vector. The formula for calculating an average is x̄ = ∑xi / n where xi is the value of each grade and n is the total number of grades in the vector. A member function to determine the lowest…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr