Create a program which uses each struct declared in problem 1 and accesses each member of each struct. (a) Create a variable using each struct and initialize it with some mock data of your choosing. (b) Print the members of each struct separated by a newline. (c) Modify each member of each struct to something different. (d) Print all members again. Save your code as prob2.c.
This is Problem 1:
struct ProductData
{
int ID;
char Name[50];
float Price;
int Quantity;
};
struct CustomerData
{
int ID;
char name[50],Address[100];
string Email;
};
struct SalesData
{
long ID,ProductID;
long salseamount;
char name[50],Address[100];
string Email[40];
};
a) product data with the following members...
struct ProductData
{
int ID;
char Name[50];
float Price;
int Quantity;
};
b) Customer Data with the following members...
struct CustomerData
{
int ID;
char name[50],Address[100];
string Email;
};
c)Sales Data with the following members...
struct SalesData
{
long ID,ProductID;
long salseamount;
char name[50],Address[100];
string Email[40];
};
The below-Mentioned Code is in C++;
#include<bits/stdc++.h>
using namespace std;
//just defining of all three structures
struct ProductData
{ int ID;
char Name[50];
float Price;
int Quantity;
};
struct CustomerData
{ int ID;
char name[50],Address[100];
string Email;
};
struct SalesData
{ long ID,ProductID;
long salseamount;
char name[50],Address[100];
string Email[40];
};
int main()
{
ProductData p; // initialize and creating of Product Data Structures //assigning the demo values
p.ID=1; //assigning the demo values
p.Price=12,p.Quantity=12;
char x[50]={'R','A','V','I'};
for(int i=0;i<4;i++)
{
p.Name[i]=x[i];
}
cout<<p.ID<<" "<<p.Name<<" "<<p.Price<<" "<<p.Quantity<<"\n";
CustomerData c; // initialize and creating of Product Data Structures
c.ID=2,c.Email="122"; //assigning the demo values
char y[50]={'A','V','I'};
for(int i=0;i<3;i++)
{
c.name[i]=y[i];
}
char v[50]={'1',' ','s','t','r','e','e','t'};
for(int i=0;i<8;i++)
{
c.Address[i]=v[i];
}
cout<<c.ID<<" "<<c.Email<<" "<<c.name<<" "<<c.Address<<"\n";
SalesData s;// initialize and creating of Product Data Structures
s.ID=3,s.ProductID=12,s.salseamount=1234; //assigning the demo values
for(int i=0;i<3;i++)
{
s.name[i]=c.name[i];
}
for(int i=0;i<8;i++)
{
s.Address[i]=c.Address[i]; // (c)Modifying is done by this method so Modifying
}
cout<<s.ID<<" "<<s.ProductID<<" "<<s.salseamount<<" "<<s.name<<" "<<s.Address;
}
Get Answers For Free
Most questions answered within 1 hours.