Question

Create a program which uses each struct declared in problem 1 and accesses each member of...

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];

};

Homework Answers

Answer #1

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;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ program that Create a struct called car that has the following data members (variables): -...
C++ program that Create a struct called car that has the following data members (variables): - Color //color of the car - Model //model name of the car - Year //year the car was made - isElectric //whether the car is electric (true) or not (false) - topSpeed //top speed of the car, can be a decimal. code i have done struct not working properly. #include <iostream> using namespace std; struct Car { string color; string model_number; int year_model; bool...
Java assignment: You are tasked with building a BookStore. Your Architect has told you that the...
Java assignment: You are tasked with building a BookStore. Your Architect has told you that the BookStore class has the following members : long id; String name; Address address; Book book; The Address class has the following attributes : String streetName; String houseNumber; String apartmentNumber; String zipCode; The book class has the following members String name; String isbn; Author author; The Author class within the book class has the following member : String firstName; String lastName; Date dateOfBirth; Address address;...
Create a class hierarchy to be used in a university setting. The classes are as follows:...
Create a class hierarchy to be used in a university setting. The classes are as follows:  The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last...
Only use C for this problem. To start, create a structure with arrays. Any structure you...
Only use C for this problem. To start, create a structure with arrays. Any structure you decide on is ok, just create your own. That said, you are required to meet these guidelines: 1. You must give the structure you make a name. Any is ok 2. Your structure must have at least 3 members. 3. Two of those members must be arrays. 4. Your members need to be of at least two different data-types. To clarify, your members cannot...
In the following C code, Which variable if NOT of primitive data type? A. a B....
In the following C code, Which variable if NOT of primitive data type? A. a B. b C. c D. d int a = 10; double b = 20.0; float c = false; char d[5] = "Hello"; // here we define a string In programming language C, the implementation of a string data type is limited dynamic length, which means the length of a string variable is fixed once it has been defined. A. True B. False In C# programming...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
currently the code contacts the server 1 time and exits. Modify the code so that the...
currently the code contacts the server 1 time and exits. Modify the code so that the program contacts the server five times before exiting. /* client.c - code for example client program that uses TCP */ #ifndef unix #define WIN32 #include <windows.h> #include <winsock.h> #else #define closesocket close #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #endif #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #define PROTOPORT 5193 /* default protocol port number */ extern int errno; char...
In this assignment, you’ll make an inventory system for a store’s items, including produce and books....
In this assignment, you’ll make an inventory system for a store’s items, including produce and books. The starter program is an inventory system for only produce. 1. Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item. Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars. Modify the AddItemToInventory...