In: Computer Science
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.
#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;
}
