Deadlines/Announcements

😫 Project 5 due 9PM Sunday, March 6th

this week’s slides: bit.ly/cs31w22_week8

last week’s slides: bit.ly/cs31w22_week7

home page: bit.ly/cs31w22

credit: nikki woo+zhehui+rosemary

Today's Agenda

Structs

collection of data treated as its own special data type.

// used to create a custom object with data types and identifiers
// of your choice

struct MenuItem
{
	string name;
	string description;
	double price;
};    // <- remember the semi colon

//Can have public, private member variables.
//Private Member Variables cant be accessed by outside
//of struct, more on this later
struct MenuItem
{
	public:
		string name;
		string description;
		double price;

	private:
		string internal_id;
};  
// how to declare and initialize struct object
MenuItem pho;
pho.name = "Pho"; // . operator used to access objects within struct
pho.description = "Vietnamese noodle dish";
pho.price = 12.31;

pho.internal_id; // error, not able because its private

// pointers and structs
MenuItem* pho_pointer = &pho;
// uses arrow operator:
// pho_pointer->name same as pho.name same as *(pho_pointer).name
// use -> when the left hand side is a **pointer**
// use . when the left hand side is the struct object