问问关于SPG的2个问题# Money - 海外理财
g*x
1 楼
以前曾经去过一次西雅图,过几天又要去了
感觉面试的时候设计题是我的软肋,答的时候总是磕磕绊绊的
想跟大家一起来讨论一下
以下列出一些我自己遇到过的或者在网上见过的题
欢迎大家讨论,补充
1. DB design of sys that enable paid customers to park, customers can either
book online beforehead or park at empty positions that are not booked
table Lot(id(pk), position, occupied);
table Customer(id(pk), name, phone);
table Lot_Customer(lid(pk), cid, start_time(pk), end_time);
2. OOD deck of cards
class Card {
enum Suits suit;
int value;
// getters & setters(check if suit & value are valid)
};
class Deck{
list cards;
Deck();
void shuffle();
Card front();
};
3. DB design of fridge inventory, can store products of different kinds,
different amounts and measurements/units (1 gallon milk, 2 dozen eggs),
expiration date (面试官不断加要求,搞得乱七八糟)
table Inventory(pid, exp_date, quantity, measurement)
table Product(pid, name)
table Type(tid, name, related_tid, relationship) // e.g. A-brand reduced fat
milk is Milk, B-brand full fat milk is also Milk, C-brand strawberry yogurt
is Yogurt, D-brand peach yogurt is also Yogurt, Milk and Yogurt are both
subtype of Dairy
table ProdType(tid, pid) // n to n relationship, each product can fall in
many types
table Measurement(pid, valid_measurement) // e.g. milk can be measured by "
gallon", "box", but not "bag"
4. OOD of a zoo, different types of animals (carnivores/herbivores,
hierarchical inheritance), cages (cage type, cage size, number of each type
of animal can be in the same cage), some of them cannot be put in the same
cage, need predator and prey relationships, what if, for instance, lion eat
1million different animals? i told him i can just put Herbivores in the prey
list of lion. he then asked what if mouse is herbivore, and lions don't eat
mice? (此题也是不断加要求,搞得相当乱)
5. OOD of elevator (道听途说,不知道原题有哪些要求)
class Elevator {
int curr_floor;
int capacity; // check if it's over-weight
int direction; // up, down, stop
list stop_floors;
void addStop(); // when button is pressed inside elevator
bool isStop(); // check if the elevator should stop at current floor
according to elevator algorithm
bool isOverweight();
void stopElev(); // open and close door, check weight, delete stop from
stop_floors list
};
class ElevGroup {
vector elevators;
list stop_floors;
void addStop(); // when button is pressed outside elevator
void schedule(); // pick an elevator and call elev.stopElev()
};
感觉面试的时候设计题是我的软肋,答的时候总是磕磕绊绊的
想跟大家一起来讨论一下
以下列出一些我自己遇到过的或者在网上见过的题
欢迎大家讨论,补充
1. DB design of sys that enable paid customers to park, customers can either
book online beforehead or park at empty positions that are not booked
table Lot(id(pk), position, occupied);
table Customer(id(pk), name, phone);
table Lot_Customer(lid(pk), cid, start_time(pk), end_time);
2. OOD deck of cards
class Card {
enum Suits suit;
int value;
// getters & setters(check if suit & value are valid)
};
class Deck{
list
Deck();
void shuffle();
Card front();
};
3. DB design of fridge inventory, can store products of different kinds,
different amounts and measurements/units (1 gallon milk, 2 dozen eggs),
expiration date (面试官不断加要求,搞得乱七八糟)
table Inventory(pid, exp_date, quantity, measurement)
table Product(pid, name)
table Type(tid, name, related_tid, relationship) // e.g. A-brand reduced fat
milk is Milk, B-brand full fat milk is also Milk, C-brand strawberry yogurt
is Yogurt, D-brand peach yogurt is also Yogurt, Milk and Yogurt are both
subtype of Dairy
table ProdType(tid, pid) // n to n relationship, each product can fall in
many types
table Measurement(pid, valid_measurement) // e.g. milk can be measured by "
gallon", "box", but not "bag"
4. OOD of a zoo, different types of animals (carnivores/herbivores,
hierarchical inheritance), cages (cage type, cage size, number of each type
of animal can be in the same cage), some of them cannot be put in the same
cage, need predator and prey relationships, what if, for instance, lion eat
1million different animals? i told him i can just put Herbivores in the prey
list of lion. he then asked what if mouse is herbivore, and lions don't eat
mice? (此题也是不断加要求,搞得相当乱)
5. OOD of elevator (道听途说,不知道原题有哪些要求)
class Elevator {
int curr_floor;
int capacity; // check if it's over-weight
int direction; // up, down, stop
list
void addStop(); // when button is pressed inside elevator
bool isStop(); // check if the elevator should stop at current floor
according to elevator algorithm
bool isOverweight();
void stopElev(); // open and close door, check weight, delete stop from
stop_floors list
};
class ElevGroup {
vector
list
void addStop(); // when button is pressed outside elevator
void schedule(); // pick an elevator and call elev.stopElev()
};