Question

In: Computer Science

C++ C++ Write a definition for a structure type for records for CDs. The record contains...

C++

C++

Write a definition for a structure type for records for CDs. The record contains price and total number of songs, . Part of the problem is appropriate choices of type and member names.Then declare two variables of this structure. Write a function called GetData use the structure as function argument to ask the user to input the value from the keyboard for structure variables.

Solutions

Expert Solution


#include <iostream>

using namespace std;

struct cd 
{
    int price;//defining structure members
    int tot_sng;
};

void GetData(struct cd *a)
{
    int price,tot_sng;
    cout<<"Enter the price :";
    cin>>price;
    cout<<"Enter the total number of songs :";
    cin>>tot_sng;
    a->price=price;//assigning user input to members of structure
    a->tot_sng=tot_sng;
}


int main()
{
    
    struct cd a,b;
    GetData(&a);//passing structure variable as reference
    GetData(&b);/*pass by reference in order to get the values enetered in Getdata function everyehere*/
    cout<<"A :"<<a.price<<" "<<a.tot_sng<<"\n";/*print statement to know the values are availablein main function also*/
    cout<<"B :"<<b.price<<" "<<b.tot_sng;
    return 0;
}


Related Solutions

C++ Write a definition for a structure type for records for books. The record contains ISBN...
C++ Write a definition for a structure type for records for books. The record contains ISBN number, price, and book cover (use H for Hard cover and P for paper cover). Part of the problem is appropriate choices of type and member names. Then declare two variables of the structure. Write a function called GetData use the structure as function argument to ask the user to input the value from the keyboard for structure variables.
In C++ Write the definition for following methods of List data structure. 5. pushFront – The...
In C++ Write the definition for following methods of List data structure. 5. pushFront – The function appends an element in the list at the front. The operation increases the number of elements in the list by one. 6. pushback - The function appends an element in the list at the end. The operation increases the number of elements in the list by one. 7.popFront - The function returns and then removes an element in the list from the front....
In C++ Write the definition for following methods of List data structure. 1. setList – The...
In C++ Write the definition for following methods of List data structure. 1. setList – The function set the value of list elements equal to a value passed as the function input. 2. getAt – The function returns an element of the list referred by its position which is given to the function as input. 3. insertAt – The function inserts a given element passed as function input in the list at the specified position also passed as second function...
Write a C program that contains a structure that uses predefined types and union. • Create...
Write a C program that contains a structure that uses predefined types and union. • Create a struct with name, age, kind (Either child, college student, or adult), and kindOfPerson (Either kid, student, or adult) • kids have a school field. Students have college and gpa. Adults have company and salary. • Create one non-dynamic struct with the content for a college student: "Bob", 20, K-State, 3.5 • Create one struct dynamically for a kid with: "Alison", 10, "Amanda Arnold...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes: Book Title (character string); Book Author (character string); Book Price (Floating point number having two decimal places); Count of books on hand (int); The member functions are as follows: A constructor that is used to initialize all four elements of the structure to values inputted by the user; A function that displays in a readable tabular form the contents of...
PLEASE USE ASSEMBLY LANGUAGE The database students.db contains student records. Each record contains a name (30B...
PLEASE USE ASSEMBLY LANGUAGE The database students.db contains student records. Each record contains a name (30B ASCII), student ID (9B ASCII), 3 grades out of 100 (3B integers), and a letter grade (1B ASCII). For the file students.db described above, assume all records are ordered alphabetically based on the name field. A record for a new student has been entered and stored in memory. Determine how to insert the new record into the database (Hint: use string compares to determine...
Coronado Industries produces 60000 CDs on which to record music. The CDs have the following costs:...
Coronado Industries produces 60000 CDs on which to record music. The CDs have the following costs: Direct Materials $11000 Direct Labor 13000 Variable Overhead 4500 Fixed Overhead 7000 None of Coronado Industries’s fixed overhead costs can be reduced, but another product could be made that would increase profit contribution by $4000 if the CDs were acquired externally. If cost minimization is the major consideration and the company would prefer to buy the CDs, what is the maximum external price that...
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName,...
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName, lastName, startYear. recordID is an integer. In testRecord, first create a record (record1) using “normal” pointers. Set the values to 1001, Fred, Flintstone, 1995 In testRecord, create a new record (record2) using a unique smart pointer. Set the values to 1002, Barney, Rubble, 2000 Create a function (or functions) that will print the records to any output stream. Since the print function does not...
For CdS in the wurtzite structure the lattice constants are specified by a= 4.14 A and...
For CdS in the wurtzite structure the lattice constants are specified by a= 4.14 A and c= 1.62 a. Calculate the density of the crystal and the volume of the primitive unit cell. What is the number of nearest neighbors and the distance between them? How many atoms does the primitive unit cell contain?
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT