Structure in C++:
Structure is a user defined datatype that is used to combine data items of different data types.
Defining a Structure:
In order to define a structure, the “struct” statement is used. This statement defines a new data type with more than one member.
struct [structure tag] {
member definition;
member definition;
...
Member definition;
}[one or more structure variables];
Here, the “structure tag” is optional and each member definition is a normal variable definition. Specifying one or more structure variables at the end of the structure definition is also optional.
Given:
The type definition for “ShoeType” is as follows.
//Define a structure
struct ShoeType
{
//Declare variables
char style;
double price;
};
The following function declaration is given.
ShoeType discount(ShoeType oldRecord);
//Returns a structure that is the same as its argument,
//but with the price reduced by 10%.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Problem Solving with C++ (10th Edition)
- 9-Given the code segment below, what should be the data type of the formal parameter in the function prototype of func(), given the call from main()? Note that function prototypes need not include the identifier (name of the parameter), so do NOT put any variable name in your answer. Remove any space in your answer. If the accessing is wrong, answer INVALID (in all capital letters). void func( ______ ); int main() { double aData[6][4]; func(&aData[4]); return 0; }arrow_forwardDefine the term void functions.arrow_forwardDefine Function evaluateExpression.arrow_forward
- INSTRUCTIONS: Write a C++ script/code to do the given problems. MOVIE PROBLEM: Write a function that checks whether a person can watch an R18+ rated movie. One of the following two conditions is required for admittance: The person is atleast 18 years old. • They have parental supervision. The function accepts two parameters, age and isSupervised. Return a boolean. Example: acceptIntoMovie(14, true) → true acceptIntoMovie(14, false) → falsearrow_forwardMUST BE DONE IN C++.arrow_forwardWrite a function template named maximum. The function takes two values of the same type as its arguments and returns the larger of the two arguments (or either value if they are equal). Give both the function declara-tion and the function definition for the template. You will use the operator< in your definition. Therefore, this function template will apply only to types for which < is defined. Write a comment for the function declaration that explains this restriction.arrow_forward
- Prototype and functional call pleasearrow_forwardHelp me with C++ please: Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class. Input should be format month day year with each separated by a space. Output should resemble the following: Date #: month-day-year An example of the program is shown below: Date 1: 3-15-2008 this is a leap year There are 3 tabs: dateType.h, dateTypelmp.cpp, main.cpp dateType.h: #ifndef date_H #define date_H class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year int getDay() const; //Function to return the day.…arrow_forwardC++ PE04 - Functions and Prototypes For this exercise, you'll complete two problems. Problem 1 - Function Declarations Write the prototypes for several function calls, deducing the correct signature from the context in PrototypeTester.cpp Do not implement the functions themselves. That is already done. Place the prototypes in pe04.h. Problem 2 - Write a Function Write a function named binToDec() that accepts an integer parameter whose digits are meant to represent binary (base-2) digits, and converts that integer's representation to decimal (base-10). The function should return the integer value before it was converted. For example, given this code: int a = 101011; int b = binToDec(a); cout << "a->" << a << ", b->" << b << endl; The output is: a->43, b->101011 Constraints: Do not use a string in your solution. Also do not use any built-in base conversion functions from the system libraries. You must program this by "hand". pe04.cpp 1 2 3…arrow_forward
- Use P, L or E to answer whether the line of code being presented isPrototype (P),Function call (L), orFunction Header (E).arrow_forwardAssume there is a function called mystery. It already has the following prototype: void mystery(bool flag); Which of the following prototypes would not be considered a proper overload for mystery? void mystery(bool valid); void mystery(string msg, double x); void mystery(int num); void mysteryO:arrow_forwardWrite a C++ program in which a class having two data members of integer type and three functions input, output and operator overloading functions, these functions will perform the following tasks: Input function initializes the data member a = 100 and b = 22. Use ‘- ‘operator as a function to decrement the vales of object using Unary operator. Output function displays the results.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education