Description
This assignment covers previous topics studied in this course along with structures and
dynamic memory allocation.
1. Create a struct for the following groups of data:
(a) Product Data with the following members
• ID
• Name
• Price
• Quantity
(b) Customer Data with the following members
• ID
• Name
• Address
• E-mail
(c) Sales Data with the following members
• Customer ID
• Product IDs
• Sale amount
• Choose the types that you think will work best for the above descriptions.
• Names should have a maximum size of 50.
• Physical addresses should have a maximum size of 100.
• E-mail addresses should have a maximum size of 40.
• Save your file as prob1.h.
2. 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.
CSE 1320: Assignment 6 Dillhoff
Save your code as prob2.c.
3. Create a program which uses the customer data struct defined in problem 1 to
store raw data input from a given CSV file. Create an array of struct to hold all
the data given in the file. This array should be a static array with a size of 100.
When reading the file, each line of raw input should be tokenized and assigned to
the appropriate members of the struct.
Create a separate function for customer data which takes the customer struct as
input and prints all the stored data using the following output constraints:
• ID: %-10d
• Name: %-25s
• Address: %-30s
• E-mail: %-25s
Your implementation should adhere to the following:
• The data file should be passed as a command line argument.
• If the given file does not exist or cannot open, warn the user.
• Save your code as prob3.c.
4. Create a program that reads and writes customer data from and to a file using
fread() and fwrite(). The data will support the customer struct defined in
problem 1.
Your program should include a menu that allows the user to list customer data or
add a new customer. It should keep the user inside the program until they choose
an option to exit.
• The data file should be passed as a command line argument.
• If the file cannot be opened, warn the user.
• Save your code as prob4.c.
Example Run – Adding Customers
1. List Customers
2. Add Customer
3. Exit
> 2
Enter ID: 1000
Enter Name: Toby Flenderson
Enter Address: Scranton, PA
Enter E-mail: hr@dundermifflin.com
User added!
Example Run – List Customers
2
CSE 1320: Assignment 6 Dillhoff
1. List Customers
2. Add Customer
3. Exit
> 1
1000 Toby Flenderson Scranton, PA hr@dundermifflin.com
5. Create a program that uses typedef to declare a new type vec2df which is a fixed
double array of size 2. Next, create another type using typedef to declare a struct
which has a fixed double array of size 2. Name this type vec2d.
In main, declare two variables which use the types created above. Using stdlib.h,
print the size of each variable on a new line and observe the similarity or difference.
Finally, create two functions which take as input the types declared above as a
single argument. For example, the first function takes vec2df as an argument and
the second takes vec2d. In each function, print the size of the argument. Observe
the difference in size between each instance.
Save your code as prob5.c.
Create a zip file using the name template LASTNAME_ID_A6.zip which includes the all
required code files. Submit the zip file through Canvas.
3