Skip to content

Commit 5ac4454

Browse files
committed
Finish
1 parent dfd5e21 commit 5ac4454

File tree

3 files changed

+384
-5
lines changed

3 files changed

+384
-5
lines changed

assign1/main.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ const std::string COURSES_NOT_OFFERED_PATH = "student_output/courses_not_offered
2525
* Hint: Remember what types C++ streams work with?!
2626
*/
2727
struct Course {
28-
/* STUDENT TODO */ title;
29-
/* STUDENT TODO */ number_of_units;
30-
/* STUDENT TODO */ quarter;
28+
std::string title;
29+
std::string number_of_units;
30+
std::string quarter;
3131
};
3232

3333
/**
@@ -58,8 +58,21 @@ struct Course {
5858
* @param filename The name of the file to parse.
5959
* @param courses A vector of courses to populate.
6060
*/
61-
void parse_csv(std::string filename, std::vector<Course> courses) {
61+
void parse_csv(std::string filename, std::vector<Course>& courses) {
6262
/* (STUDENT TODO) Your code goes here... */
63+
std::ifstream ifs_courses(filename); // create and open
64+
65+
if (!ifs_courses.is_open()) {
66+
std::cerr << "This file open failed." << filename << std::endl;
67+
}
68+
69+
std::string line;
70+
while (std::getline(ifs_courses, line)) {
71+
std::vector<std::string> parts = split(line, ',');
72+
Course course { parts[0], parts[1], parts[2] };
73+
courses.push_back(course);
74+
}
75+
ifs_courses.close();
6376
}
6477

6578
/**
@@ -82,6 +95,19 @@ void parse_csv(std::string filename, std::vector<Course> courses) {
8295
*/
8396
void write_courses_offered(std::vector<Course> all_courses) {
8497
/* (STUDENT TODO) Your code goes here... */
98+
std::ofstream ofs_all_courses("student_output/courses_offered.csv", std::ios::trunc);
99+
100+
for (const Course& course : all_courses) {
101+
if (ofs_all_courses.is_open() && course.quarter != "null") {
102+
ofs_all_courses << course.title << "," << course.number_of_units << "," << course.quarter << std::endl;
103+
}
104+
}
105+
ofs_all_courses.close();
106+
107+
Course course;
108+
if (course.quarter == "null") {
109+
delete_elem_from_vector(all_courses, course);
110+
}
85111
}
86112

87113
/**
@@ -99,6 +125,20 @@ void write_courses_offered(std::vector<Course> all_courses) {
99125
*/
100126
void write_courses_not_offered(std::vector<Course> unlisted_courses) {
101127
/* (STUDENT TODO) Your code goes here... */
128+
std::ofstream ofs_all_courses("student_output/courses_not_offered.csv", std::ios::trunc);
129+
130+
ofs_all_courses << "Title" << "," << "Number of Units" << "," << "Quarter" << std::endl;
131+
for (const Course& course : unlisted_courses) {
132+
if (ofs_all_courses.is_open() && course.quarter == "null") {
133+
ofs_all_courses << course.title << "," << course.number_of_units << "," << course.quarter << std::endl;
134+
}
135+
}
136+
ofs_all_courses.close();
137+
138+
Course course;
139+
if (course.quarter != "null") {
140+
delete_elem_from_vector(unlisted_courses, course);
141+
}
102142
}
103143

104144
int main() {
@@ -109,10 +149,11 @@ int main() {
109149
parse_csv("courses.csv", courses);
110150

111151
/* Uncomment for debugging... */
112-
// print_courses(courses);
152+
print_courses(courses);
113153

114154
write_courses_offered(courses);
115155
write_courses_not_offered(courses);
116156

117157
return run_autograder();
158+
118159
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
Title,Number of Units,Quarter
2+
Introduction to Computing at Stanford (VPTL 1),1,null
3+
Practical Unix,1,null
4+
Problem-Solving for the CS Technical Interview,1,null
5+
Introduction to Version Control with Git,1,null
6+
Beyond NLP: CS & Language through Text Input & Design,1,null
7+
Hap.py Code: The Python Programming Language,2,null
8+
Functional Programming Abstractions,2,null
9+
Software Tools Every Programmer Should Know,2,null
10+
Working with Data: Delights and Doubts,3,null
11+
Cross-Platform Mobile Development,2,null
12+
Using Tech for Good,2,null
13+
Great Discoveries and Inventions in Computing,3,null
14+
Randomness: Computational and Philosophical Approaches (PHIL 3N),3,null
15+
You Say You Want a Revolution (Blockchain Edition),2,null
16+
The Blockchain Revolution Will Not Be Televised,3,null
17+
Quantum Computing: Open-Source Project Experience,2,null
18+
Computation for Puzzles and Games,1,null
19+
Race and Gender in Silicon Valley (AFRICAAM 80Q),3,null
20+
AI Interpretability and Fairness,1,null
21+
Wellness in Tech: Designing an Intentional Lifestyle in a Tech-Driven World,1,null
22+
Emotional Intelligence,2,null
23+
Digital Canvas: An Introduction to UI/UX Design,2,null
24+
Digital Canvas: An Introduction to UI/UX Design,2,null
25+
Teaching AI,1,null
26+
Introduction to Computing Principles,5,null
27+
Working with Data - Tools and Techniques,4,null
28+
Programming Abstractions (Accelerated),5,null
29+
Principles of Computer Systems,5,null
30+
Problem Solving Lab for CS110,1,null
31+
Safety in Systems Programming,2,null
32+
Selected Reading of Computer Science Research,3,null
33+
Human Centered NLP (CS 329X),4,null
34+
Human-Centered AI,3,null
35+
Operating Systems and Systems Programming,5,null
36+
Web Applications,3,null
37+
Introduction to Game Design and Development,4,null
38+
The Practice of Theory Research,3,null
39+
Data Structures,4,null
40+
Effective Leadership in High-Tech,1,null
41+
Bridging Policy and Tech Through Design (PUBLPOL 170),4,null
42+
Design for Advocacy,4,null
43+
Android Programming,3,null
44+
iOS Application Development,3,null
45+
Video Game Development in C++ and Unreal Engine,3,null
46+
Web Programming Fundamentals,3,null
47+
Android Programming Workshop,1,null
48+
Computer Consulting (VPTL 196),2,null
49+
Computational Law,3,null
50+
Antidiscrimination Law and Algorithmic Bias,3,null
51+
Great Ideas in Computer Science,3,null
52+
Creating Great VR: From Ideation to Monetization,1,null
53+
Selected Reading of Computer Science Research,3,null
54+
Hardware Accelerators for Machine Learning,4,null
55+
The Future of Mechanical Engineering (ME 228),1,null
56+
Computer Vision and Image Analysis of Art,3,null
57+
Digital Image Processing (EE 368),3,null
58+
Generative Adversarial Networks,3,null
59+
Principles of Data-Intensive Systems,4,null
60+
Mining Massive Data Sets Hadoop Lab,1,null
61+
Design for Understanding,4,null
62+
Algebraic Error Correcting Codes (EE 387),3,null
63+
Analysis of Boolean Functions,3,null
64+
Web Security,3,null
65+
Geometry of Polynomials in Algorithm Design,3,null
66+
Geometric Algorithms,3,null
67+
Almost Linear Time Graph Algorithms (MS&E 313),3,null
68+
Introduction to Optimization Theory (MS&E 213),3,null
69+
Elements of Quantum Computer Programming,3,null
70+
Information Retrieval and Web Search (LINGUIST 286),3,null
71+
Research Project in Artificial Intelligence,3,null
72+
Research Project in Software Systems and Security,3,null
73+
Writing Intensive Research Project in Computer Science,3,null
74+
Industrial Lectureships in Computer Science,1,null
75+
Parallel Computing Research Project,3,null
76+
Advanced Multi-Core Systems,3,null
77+
Topics in Digital Systems,3,null
78+
Value of Data and AI,3,null
79+
The AI Awakening: Implications for the Economy and Society,4,null
80+
The AI Awakening: Implications for the Economy and Society,3,null
81+
Advances in Foundation Models,3,null
82+
Topics in Artificial Intelligence,3,null
83+
Machine Learning Under Distributional Shifts,3,null
84+
Machine Learning on Embedded Systems (EE 292D),3,null
85+
Practical Machine Learning,4,null
86+
Machine Learning Systems Design,4,null
87+
Human Centered NLP (CS 129X),4,null
88+
Interactive Simulation for Robot Learning,3,null
89+
Advanced Survey of Reinforcement Learning,3,null
90+
Algorithms for Interactive Robotics,4,null
91+
Physical Human Robot Interaction,3,null
92+
Human-Computer Interaction and AI/ML,3,null
93+
Topics in Computer Systems,4,null
94+
Advanced Operating System Lab: Accelerated (II),2,null
95+
Project in Mining Massive Data Sets,3,null
96+
Topics in Computer Networks,3,null
97+
Data-intensive Systems for the Next 1000x,4,null
98+
Computer Graphics: Geometric Modeling & Processing,3,null
99+
Computer Graphics: Image Synthesis Techniques,4,null
100+
Neural Models for 3D Geometry,3,null
101+
Topics in Programming Systems,3,null
102+
Technology for Financial Systems,2,null
103+
Selected Reading of Ph.D. Dissertations,3,null
104+
Machine Learning for Software Engineering,4,null
105+
Project Lab: Video and Audio Technology for Live Theater in the Age of COVID (EE 192T),3,null
106+
Secure Compilation,3,null
107+
Open Problems in Coding Theory,3,null
108+
Blockchain Governance,3,null
109+
Topics in Intractability: Unfulfilled Algorithmic Fantasies,3,null
110+
Advanced Topics in Formal Methods,3,null
111+
Formal Methods for Computer Systems,3,null
112+
Topics in Programming Language Theory,3,null
113+
Programming Language Foundations,3,null
114+
Topics in the Theory of Computation,3,null
115+
Research Seminar in Complexity Theory,3,null
116+
Quantum Complexity Theory,3,null
117+
Simplicity and Complexity in Economic Theory (ECON 284),5,null
118+
Research in AI Alignment,3,null
119+
Algorithmic Techniques for Big Data,3,null
120+
Topics in Analysis of Algorithms,3,null
121+
Algorithmic Perspective on Machine Learning,3,null
122+
Metric Embeddings and Algorithmic Applications,3,null
123+
Dynamic Data Structures for Graphs,3,null
124+
Topics in Human-Computer Interaction,3,null
125+
Designing Solutions to Global Grand Challenges (DESIGN 297),4,null
126+
Introduction to the Design of Smart Products (ME 216M),4,null
127+
Topics in Human-Computer Interaction: Teaching Studio Classes,3,null
128+
Computational Models of the Neocortex,3,null
129+
Sensorimotor Learning for Embodied Agents (EE 381),3,null
130+
Seminar on Ethical and Social Issues in Natural Language Processing (LINGUIST 287),4,null
131+
Computational Education,4,null
132+
Designing AI to Cultivate Human Well-Being,2,null
133+
Probabilistic models of cognition: Reasoning and Learning (PSYCH 220A),3,null
134+
High-level Vision: From Neurons to Deep Neural Networks (PSYCH 250),3,null
135+
Topics in Computer Graphics,4,null
136+
Topics in Computer Graphics: Agile Hardware Design,3,null
137+
Making Making Machines for Makers,4,null
138+
Hacking the Pandemic,3,null
139+
Topics in Computer Graphics: Computational Video Manipulation,3,null
140+
Physically Based Animation and Sound,4,null
141+
Topics in Geometric Algorithms: Non-Euclidean Methods in Machine Learning,3,null
142+
Digital Technology and Law: Foundations,3,null
143+
Knowledge Graphs,1,null
144+
Seminar on AI Safety,1,null
145+
Research Seminar in Computer Vision + X,2,null
146+
Research Seminar in Computer Vision and Healthcare,1,null
147+
Human-Computer Interaction in the Real World,1,null
148+
Surgical Robotics Seminar (ME 571),1,null
149+
Media Innovation,1,null

0 commit comments

Comments
 (0)