Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignments Partially Completed #71

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions session_1/solution/courses.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Importing dart:io and our electives classes from electives.dart
import 'dart:io';
import 'coursesModule/electives.dart';

// Main Function
void main(){

bool running = true; //Condition for loop to run

while(running){

print("\nEnter type of user 1.Admin 2.Student 3.Exit"); //User input for user type
String choice = stdin.readLineSync()!;


if(choice == "2"){
print("\nEnter Branch and year (eg. cs 2):");
List details = stdin.readLineSync()!.split(" "); // If student, user can type branch and year
//to get its branch and open electives

print("Your Branch Electives: ${BranchElectives.getList(details)}"); // Calling static getList functions of branch
print("Open Electives: ${OpenElectives.getList()}"); // and open electives

}


else if(choice == "1"){
bool adminLoopRunning = true;
while(adminLoopRunning){ // Running an admin loop

print("\nEnter type of Elective 1.Branch Elective 2.Open Elective 3.Exit"); // Enter choice for elective type
String electiveChoice = stdin.readLineSync()!;

if(electiveChoice == "1"){
print("\nEnter Operation Choice 1.View Courses 2.Add Course"); // Enter choice for operation to perform on
String operationChoice = stdin.readLineSync()!; // branch elective

if(operationChoice == "1") print("Branch Electives: ${BranchElectives.getFullList()}"); // Calling function to print all branch electives

else if(operationChoice == "2") {
print("\nEnter new Course details (eg. courseName courseCode branch year):"); // To add a new course
String courseDetails = stdin.readLineSync()!;
BranchElectives.addCourse(courseDetails);
}
}

else if(electiveChoice == "2"){
print("\nEnter Operation Choice 1.View Courses 2.Add Course"); // Enter choice for operation to perform on
String operationChoice = stdin.readLineSync()!; // open elective

if(operationChoice == "1") print("Open Electives: ${OpenElectives.getList()}"); // print all open electives

else if(operationChoice == "2") {
print("\nEnter new Course details (eg. courseName courseCode):");
String courseDetails = stdin.readLineSync()!; // To add a new course
OpenElectives.addCourse(courseDetails);
}
}

else if(electiveChoice == "3") adminLoopRunning = false; // end admin loop
else print("\nInvalid Choice\n"); // input error handling
}
}

else if(choice == "3") running = false; // ending program loop
else print("\nInvalid Choice\n"); // input error handling
}

}
6 changes: 6 additions & 0 deletions session_1/solution/coursesModule/branchElectives.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OOPS,cs200,cs,2
SigPrsc,ec209,ec,2
MicroControllers,ec301,ec,3
C++,cs102,cs,1
EngMech,me101,me,1
EngDraw,cv111,cv,1
92 changes: 92 additions & 0 deletions session_1/solution/coursesModule/electives.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//Importing dart:io for file handling
import 'dart:io';

// Defining an abstract class electives to define basic functionalities of an elective class
abstract class Electives{
abstract String courseName;
abstract String courseCode;

}

// Defining our Branch Electives Class
class BranchElectives extends Electives{

var courseName, courseCode, branch, year;

BranchElectives(this.courseName, this.courseCode, this.branch, this.year); // Constructor

static List getList(List details){ // To get list of branch electives corresponding to given branch and year

File file = File('./coursesModule/branchElectives.txt'); // Read our Branch electives list from branchElectives.txt
List lines = file.readAsLinesSync();

List line = [];
lines.forEach((element) => line.add(element.split(","))); // Converting to list

List courses = [];
line.forEach((element) {
if(details[0] == element[2] && details[1] == element[3]){ //Conditions to check
courses.add(element[0]);
}
});

return courses;
}


static List getFullList(){ // To get list of all branch electives

File file = File('./coursesModule/branchElectives.txt'); // Read our Branch electives list from branchElectives.txt
List lines = file.readAsLinesSync();

List line = [];
lines.forEach((element) => line.add(element.split(","))); // Converting to list

List courses = [];
line.forEach((element)=>courses.add(element[0])); // Formatting for return

return courses;
}

static void addCourse(String courseDetails){ // To add a course to branch elective list

String insert = courseDetails.replaceAll(" ", ","); // Formatting

File file = File('./coursesModule/branchElectives.txt');
file.writeAsStringSync("\n$insert",mode: FileMode.append); // Append new course to branchElectives.txt
print('\nCourse added.\n');
}
}




class OpenElectives extends Electives{

var courseName, courseCode;

OpenElectives(this.courseName, this.courseCode); // Constructor

static List getList(){ // To get list of Open electives

File file = File('./coursesModule/openElectives.txt');
List lines = file.readAsLinesSync(); // Read our Open electives list from openElectives.txt

List line = [];
lines.forEach((element) => line.add(element.split(","))); // Converting to list

List courses = [];
line.forEach((element)=>courses.add(element[0]));

return courses;
}

static void addCourse(String courseDetails){ // Add new course to list

String insert = courseDetails.replaceAll(" ", ","); // Formatting

File file = File('./coursesModule/openElectives.txt');
file.writeAsStringSync("\n$insert",mode: FileMode.append); // Append new course to openElectives.txt
print('\nCourse added.\n');
}
}
5 changes: 5 additions & 0 deletions session_1/solution/coursesModule/openElectives.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Python,py101
CAD,me100
FuelTechnology,cy203
AppDev,cs215
Ruby,rb101
39 changes: 39 additions & 0 deletions session_1/solution/fibonacci.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Importing dart:io to implement input from user
import 'dart:io';

// Recursive Function to print Fibonacci Sequence
void printFib(int n, int a, int b){
if (n == 0){
return;
}
int c = a+b;
stdout.write("$c ");
printFib(n-1,b,c);
}

// Main Function
void main(){

print("\n\n\n################################");

print("PRINTING FIBONACCI SEQUENCE");

print("################################\n\n\n");

stdout.write("Enter number of terms of Fibonacci numbers to print: ");
int? n = int.parse(stdin.readLineSync()!); // Taking input from user

int a = 0;
int b = 1;

stdout.write("\n Fibonacci series upto $n terms: ");

if(n < 1) print("\nInvalid Input");
else if (n == 1) stdout.write("$a "); // Base cases
else if (n == 2) stdout.write("$a $b "); // Base cases
else {
stdout.write("$a $b ");
printFib(n-2,a,b); //Calling the printFib function
}
print("\n\n##################################\n\n\n");
}
34 changes: 34 additions & 0 deletions session_1/solution/semiPrime.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Importing packages dart:io for user input and dart:math for the sqrt() function
import 'dart:io';
import 'dart:math';

// Defining an isSemiPrime function to check if passed number is semiprime.
bool isSemiPrime(int n){

int countFact = 0, j = 0;
for(int i = 1; i<= sqrt(n); i++){ // Basically this loop counts the no. of factors of n, before sqrt(n).
if(n%i == 0){ // If this count equals 2, we conclude that the number is semiprime.
countFact++; // This is because a semiprime n has 4 factors (1, prime#1, prime#2, and n)
j = i; // out of which 1 and prime#1 are before sqrt(n), Thus count being 2.
} // Exception, this algorithm does not work for cubes of primes.
}

return countFact == 2 && n != pow(j, 3)? true : false;

}

// Main Function
void main(){

print("\n\n\n###############################################");
print("Checking if Input Number is Semiprime");
print("###############################################\n\n\n");

stdout.write("Enter number to check if semiprime: ");
int? n = int.parse(stdin.readLineSync()!); // Taking input from user

if(isSemiPrime(n)) print("\n$n is semi prime.");
else print("\n$n is not semi prime.");

print("\n\n#########################################\n\n\n");
}
54 changes: 54 additions & 0 deletions session_1/solution/sumOfPrime.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Importing dart:io to implement input from user
import 'dart:io';


// isPrime function to check if a number is prime
bool isPrime(n){

int count = 0;
if(n == 1){
count = 1;
}else{
for(int i = 2; i*i <= n; i++){
if (n % i == 0){
count++;
}
}
}
return count == 0 ? true : false;
}


// Main Function
void main(){

print("\n\n\n##########################################################");
print("Checking if Sum of primes of array is also Prime");
print("##########################################################\n\n\n");

stdout.write("Enter array to check (eg. 1 4 3 55 3): ");
String? n = stdin.readLineSync(); // Taking input from user

if(n != null){
var list = n.split(" ");
List<int> arr = []; // Convert user input into array/list data
list.forEach((element) => {arr.add(int.parse(element))});


int sum = 0;
arr.forEach((element) => {sum += isPrime(element) ? element : 0}); //get sum of prime elements of list

if(isPrime(sum)) print("\nSum of the primes of the array ($sum) is also prime"); // Output if sum of prime elements
else print("\nSum of the primes of the array ($sum) is not prime"); // of array is prime or not




}else print("Null input not accepted");




print("\n\n#############################################################\n\n\n");

}
46 changes: 46 additions & 0 deletions session_3/numbers_app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
10 changes: 10 additions & 0 deletions session_3/numbers_app/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b
channel: stable

project_type: app
20 changes: 20 additions & 0 deletions session_3/numbers_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# numbers_app

A new Flutter project.

## Final Result

![numbers app](https://user-images.githubusercontent.com/78261857/150091389-cb6da685-15c5-432e-a65b-94e63ff95092.gif)

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Loading