Recently, there has been a wide interest in the massive open online courses (MOOCs) that are freely available to the students from all over the world. Due to the large scale of MOOCs, the instructors (even with their teams of graders) cannot assess all the examinations and quizzes themselves. Peer grading eases the assessment burden but has its shortcomings. Ideally, the assessments should be fully automated and should also allow partial grading. Additionally, a sizeable database of questions is needed so that an individual student or a group of students are not able to see all the questions by repeatedly attempting the quizzes. In this paper, we present a Matlab-based method for automatically generating a large number of questions and their (intermediate and final) answers for a MOOC or a traditional classroom-based course on digital circuit design. The method that enables formative assessment is also applicable to other courses in engineering and sciences.