0% found this document useful (0 votes)
3 views6 pages

Mid Term Solution

The document contains solutions for a mid-term examination in Mobile Application Development at COMSATS University Islamabad. It includes tasks such as creating a Person and Student class in Dart, displaying text using Flutter widgets, implementing a counter increment functionality, and designing a simple GUI. Each task has specific requirements and marks allocated for completion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Mid Term Solution

The document contains solutions for a mid-term examination in Mobile Application Development at COMSATS University Islamabad. It includes tasks such as creating a Person and Student class in Dart, displaying text using Flutter widgets, implementing a counter increment functionality, and designing a simple GUI. Each task has specific requirements and marks allocated for completion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

COMSATS University Islamabad

Abbottabad Campus

Department of Computer Science

SOLUTION - MID TERM EXAMINATION SPRING 2024

Class: BCS 7 Section: ________ Date: _17 May 2024_


Subject: Mobile Application Development Instructor: Dr. Osman Khalid
Total Time Allowed: 1 hour Max Marks: _45_________
Student Name:__________________ Registration #______________

1. Create a class Person with attributes: id, name, age. Derive a class from person, named
Student. The extra attributes of Student are cgpa, currently enrolled semester (e.g., FA22
or SP22, etc), admission date. Populate a list with at least 3 records of Student class. Print
list of students whose cgpa is greater than 3.7. [CLO-1, C2][Marks: 15]

class Person {
String? id;
String? name;
int? age;

Person(this.id, this.name, this.age);


}

class Student extends Person {


double? cgpa;
String? semester;
String? admissionDate;

Student(super.id, super.name, super.age, this.cgpa, this.semester, this.admissionDate);


}

void main() {

List<Student> students = [
Student('123', 'John Doe', 21, 3.1, 'Fa23', '2022-09-01'),
Student('456', 'Shahid Gul', 12, 2.8, 'Fa22', '2023-09-01'),
Student('432', 'Muneeza Malik', 21, 3.9, 'Sp22', '2023-10-01'),
Student('789', 'Javed Henry', 30, 2.9, 'Sp23', '2025-09-01'),
Student('728', 'Neelam Khan', 30, 3.7, 'Sp23', '2025-09-01'),
];
students.where((student) => student.cgpa! >= 3.7).forEach((student)=>print("${student.id}
${student.name}"));

1
2. Use flutter widgets to show this on screen. The screen background color is white, but you
are not allowed to use background color property. Here ONE, TWO, THREE, FOUR
represent Text() widgets. [CLO-2, C3][Marks: 15]

ONE TWO
THREE FOUR

import 'package:flutter/material.dart';

void main() {
runApp(const MaterialApp(
home: Scaffold(
body: Center(
child: InputDisplay(),
)
)
));
}

class InputDisplay extends StatelessWidget {


const InputDisplay({super.key});

@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[

Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[Text("ONE"),Text("TWO")]
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[Text("THREE"),Text("FOUR")]
),

],
);
}

3. Create the following app, when increment button is pressed, the value of counter increases.
You just need to write the code of the following class: [CLO-3, C3][Marks: 15]

2
class _CounterState extends State<Counter> {

Counter: 0

Increment

import 'package:flutter/material.dart';

void main() {
runApp(
const MaterialApp(
home: Scaffold(
body: Center(
child: Counter(),
),
),
),
);
}

class Counter extends StatefulWidget {

const Counter({super.key});

@override
State<Counter> createState() => _CounterState();
}

class _CounterState extends State<Counter> {


int _counter = 0;

void _increment() {
setState(() {

_counter++;
});
}

@override
Widget build(BuildContext context) {

return Column(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget>[
Row(

3
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget>[

Text('Counter: $_counter'),

]
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _increment,
child: const Text('Increment'),
)] ) ,

],
);
}
}

4
COMSATS University Islamabad
Abbottabad Campus

Department of Computer Science

LAB MID TERM EXAMINATION SPRING 2024

Class: BCS 7 Section: ________ Date: _17 May 2024_


Subject: Mobile Application Development Instructor: Dr. Osman Khalid
Total Time Allowed: 30 minutes Max Marks: _10_________
Student Name:__________________ Registration #______________

(NOTE: You need to write the solution on this same question paper)

Write code to create a GUI in flutter like this:. [CLO-4, C3][Marks: 10]

This is title bar SOLUTION

(Write from here)

Hello World!

Solution:

import 'package:flutter/material.dart';

void main() {
runApp(
const MaterialApp(
title: 'Flutter Tutorial',
home: TutorialHome(),
),
);
}

class TutorialHome extends StatelessWidget {


const TutorialHome({super.key});

@override

5
Widget build(BuildContext context) {
// Scaffold is a layout for
// the major Material Components.
return Scaffold(
appBar: AppBar(
title: const Center(child: Text('This is title bar')),

),
// body is the majority of the screen.
body: const Center(
child: Text('Hello, world!'),
),
);
}
}

You might also like