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

Assignment 2 : Solved. (session_3/code/Assignment2) #49

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b51d5a8
first problem solved
Mutashimbhat96 Jan 10, 2022
c240dc1
problem 1 solved
Mutashimbhat96 Jan 10, 2022
70f095c
Problem 2 solved
Mutashimbhat96 Jan 10, 2022
12ba191
Problem 3 Solved
Mutashimbhat96 Jan 10, 2022
207e26b
added comments
Mutashimbhat96 Jan 10, 2022
f967740
Problem 4 solved
Mutashimbhat96 Jan 10, 2022
6c55ef1
fixed
Mutashimbhat96 Jan 10, 2022
b0c1f5a
Merge branch 'IRIS-NITK:master' into master
Mutashimbhat96 Jan 19, 2022
1e22fab
Added icons
Mutashimbhat96 Jan 22, 2022
f71aff9
added screen recording
Mutashimbhat96 Jan 22, 2022
114d659
added screen recording
Mutashimbhat96 Jan 22, 2022
bd04d23
added screen recording
Mutashimbhat96 Jan 22, 2022
5ac0209
added screen recording
Mutashimbhat96 Jan 22, 2022
6e5b8eb
Merge branch 'IRIS-NITK:master' into master
Mutashimbhat96 Jan 22, 2022
f8cd90a
some minor ui changes
Mutashimbhat96 Jan 22, 2022
e62c2f4
Delete 20220122_131310.gif
Mutashimbhat96 Jan 22, 2022
fdb4967
Add files via upload
Mutashimbhat96 Jan 22, 2022
3f3e514
Update README.md
Mutashimbhat96 Jan 22, 2022
48ad5d7
Delete screen.gif
Mutashimbhat96 Jan 22, 2022
319cdb3
Add files via upload
Mutashimbhat96 Jan 22, 2022
45ff9d0
Delete main.dart
Mutashimbhat96 Jan 22, 2022
fbb5d9c
Create lib
Mutashimbhat96 Jan 22, 2022
0ca2f30
Delete session_3/assignment2 directory
Mutashimbhat96 Jan 22, 2022
54e7cd7
Solved Assignment 3
Mutashimbhat96 Jan 22, 2022
9681bf2
Solved Assignment 3
Mutashimbhat96 Jan 22, 2022
b75c138
Delete session_3/assignment2 directory
Mutashimbhat96 Jan 22, 2022
f7f3c72
Merge branch 'IRIS-NITK:master' into master
Mutashimbhat96 Jan 28, 2022
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
23 changes: 23 additions & 0 deletions session_1/solutions/Problem_1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'dart:io';

// FUnction to print first N fibonacci numbers
void fibo_n(int n) {
int a = 0, b = 1;
int c = 1;
for (int i = 0; i < n; i++) {
stdout.write(" ${a}");
c = a + b;
a = b;
b = c;
}
}

//driver code
int main() {
print("Program to Print first N fibonacci numbers.");
stdout.write("Enter the limit for FIbonacci Numbers : ");
int? n = int.parse(stdin.readLineSync()!);
print("The First ${n} fibonacci numbers are : ");
fibo_n(n);
return 0;
}
47 changes: 47 additions & 0 deletions session_1/solutions/problem_2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:io';

// Function to check if a number is prime
bool isPrime(int num) {
if (num == 1) {
return false;
}
if (num < 4) {
return true;
}

for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}

// Function to check if a number is semi-prime
bool isSemiPrime(int num) {
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
int div = num ~/ i;
if (isPrime(i) && isPrime(div)) {
stdout.write("${num} = ${i} * ${div} = > ");
return true;
}
}
}
return false;
}

//driver code
int main() {
print("Program to check whether a given number is Semi-prime or not :");
print(
" Semi-prime : a number that is product of 2 prime numbers like 6,9,15 etc");
stdout.write("Enter a number : ");
int? num = int.parse(stdin.readLineSync()!);
if (isSemiPrime(num)) {
print(" ${num} is semi-Prime");
} else {
print("${num} is not semi-Prime ");
}
return 0;
}
43 changes: 43 additions & 0 deletions session_1/solutions/problem_3.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:io';

// Function to check if a number is prime
bool isPrime(int num) {
if (num == 1) {
return false;
}
if (num < 4) {
return true;
}

for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}

// driver code
int main() {
print(
"Program to check if the sum of prime numbers in an array is prime or not.");
stdout.write("Enter size of the array : ");
int? size = int.parse(stdin.readLineSync()!);
int sum = 0;
var arr = List.generate(size, (index) => index.toInt());
for (int i = 0; i < size; i++) {
stdout.write("Enter number ${i + 1} : ");
arr[i] = int.parse(stdin.readLineSync()!);
}
for (int i = 0; i < size; i++) {
if (isPrime(arr[i])) {
sum += arr[i];
}
}
if (isPrime(sum)) {
print("Sum is ${sum} and it is Prime.");
} else {
print("Sum is ${sum} and it is not Prime.");
}
return 0;
}
90 changes: 90 additions & 0 deletions session_1/solutions/problem_4.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'dart:io';

//Creating respective classes
class OpenElective {
String courseCode, courseName;
OpenElective(this.courseCode, this.courseName);
}

class BranchElective extends OpenElective {
String branch, year;

BranchElective(this.branch, this.year, String courseCode, String courseName)
: super(courseCode, courseName);
}

//Driver Code
int main() {
List<OpenElective> open_electives = [
OpenElective('OE500', 'AI')
]; //some default courses
List<BranchElective> branch_electives = [
BranchElective('CSE', '3RD', 'CS601', 'DBMS') //some default courses
];
bool check = true;
while (check) {
String branch = "", year = "", course_name = "", course_code = "";
stdout.write(
"Enter type of user 1. Admin 2. Student ,Any other number to Exit : ");
int? user = int.parse(stdin.readLineSync()!);
switch (user) {
case 1:
int course;
do {
stdout
.write("Enter course type 1.Open elective 2.Branch elective : ");
course = int.parse(stdin.readLineSync()!).toInt();
if (course < 1 || course > 2) {
print("Wrong input, Try Again ");
}
} while (course < 1 || course > 2);

stdout.write("Enter Course name : ");
course_name = stdin.readLineSync().toString().toUpperCase();
stdout.write("Enter Course code : ");
course_code = stdin.readLineSync().toString().toUpperCase();
switch (course) {
case 1:
open_electives.add(OpenElective(course_code, course_name));
break;
case 2:
stdout.write("Enter Branch and year separated by a space : ");
String b_y = stdin.readLineSync().toString();
List<String> ip = b_y.split(" ");
branch = ip[0].toUpperCase();
if (ip.length > 1) year = ip[1].toUpperCase();
// stdout.write("Enter Year : ");
// String? year = stdin.readLineSync();
branch_electives
.add(BranchElective(branch, year, course_code, course_name));
break;
default:
print("Wrong input ");
}
break;
case 2:
stdout.write("Enter Branch and year separated by a space : ");
String b_y = stdin.readLineSync().toString();
List<String> ip = b_y.split(" ");
branch = ip[0].toUpperCase();
if (ip.length > 1) year = ip[1].toUpperCase();
print("Branch Electives : ");
for (BranchElective x in branch_electives) {
if (x.branch == branch && x.year == year) {
stdout.write(
"${x.branch} ${x.year} ${x.courseCode} ${x.courseName} \n");
}
}
print("Open Electives : ");
for (OpenElective x in open_electives) {
stdout.write("${x.courseCode} ${x.courseName}\n");
}
break;
default:
check = false;
break;
}
}

return 0;
}
46 changes: 46 additions & 0 deletions session_3/code/assignment2/.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/code/assignment2/.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
21 changes: 21 additions & 0 deletions session_3/code/assignment2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# assignment2

A new Flutter project.

## 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:
Screen Recording :
<p align="center">
<img src="assets\screen.gif" />
</align>


- [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.
29 changes: 29 additions & 0 deletions session_3/code/assignment2/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
13 changes: 13 additions & 0 deletions session_3/code/assignment2/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
68 changes: 68 additions & 0 deletions session_3/code/assignment2/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.assignment2"
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Loading