You are on page 1of 15

COMPUTER SCIENCE HSSC

PRACTICAL EXAMINATION 2024


Part-I
Practical #1 Recognize Internal or external components of system unit.
Internal or external components of system unit.

Internal Component of Computer


Mother Borad
CPU (Central Processing Unit)
RAM (Random Access Memory):
Hard Drive or SSD (Solid State Drive)
Power Supply Unit (PSU):
Graphics Card (GPU)
Expansion Cards

External Component of Computer


Keyboard
Mouse or Trackpad
Monitor or Display
Speakers or Headphones:
External Storage Devices
Printer or Scanner:
Network Devices:

Internal Components:

1. Motherboard: The main circuit board that houses the CPU, RAM slots, expansion slots,
and other essential components.
2. CPU (Central Processing Unit): The brain of the computer that performs calculations
and executes instructions.
3. RAM (Random Access Memory): Temporary storage used by the CPU to store data
and program instructions that are currently in use.
4. Hard Drive or SSD (Solid State Drive): Internal storage for storing the operating
system, programs, and user data.
5. Power Supply Unit (PSU): Converts AC power from the wall outlet into DC power for
the computer's components.
6. Graphics Card (GPU): Responsible for rendering images and videos, especially in
tasks like gaming or graphic design.
7. Expansion Cards: Additional cards that can be installed into expansion slots on the
motherboard, such as sound cards, network cards, or additional USB ports.

External Components:

1. Keyboard: Input device used for typing text and issuing commands to the computer.
2. Mouse or Trackpad: Input device used for navigating graphical user interfaces and
selecting items on the screen.
3. Monitor or Display: Output device that displays the computer's graphical interface and
output.
4. Speakers or Headphones: Output devices used for audio playback.
5. External Storage Devices: Devices such as external hard drives or USB flash drives
used for additional storage.
6. Printer or Scanner: Peripherals used for printing documents or scanning images.
7. Network Devices: Devices such as routers, switches, or modems used for connecting
the computer to a network or the internet.

Practical#2: Steps of task related to computer system.


Steps:
Steps that might be involved in computer-related tasks are given as:
The five main steps are input, processing, storage, output and communication.
1.INPUT
In the input stage, the data is entered into the computer. There are many ways to do this. In fact,
there are as many ways to input data as there are input devices

2.PROCESSING
The central processing unit (CPU) inside the computer then takes that binary code and does the
calculations needed to get that data to display in a way that makes sense to the user.

3.STORAGE
Storage is where the computer takes the input and stores it in its memory banks.

4.OUTPUT
Output is where the computer takes the pixels from the processing stage and displays them in a
way that the user can see them. There are many kinds of output devices, such as printers, screens,
video and audio devices.

5.COMMUNICATION

Computer communications are any processes that allow you to communicate


which feature a computer or computer program.

Database Practical
1.Create two tables with at least five fields having different data types, also specify
appropriate primary keys.
Create relationship between them Enter at least five records using forms
Design a query or report depending on specific criteria

Create two tables in a relational database along with their fields, primary keys,
and then establish a relationship between them.

First Table: Employees Fields:


1. Employee ID (Primary Key) - AutoNumber (Numeric)
2. First Name - Text
3. Last Name - Text
4. DateOfBirth - Date/Time
5. Department ID - Number (Foreign Key referencing Department table)

Second Table: Departments Fields:

1. Department ID (Primary Key) - AutoNumber (Numeric)


2. Department Name - Text
3. Manager Name - Text
4. Location - Text
5. Budget - Currency

Relationship:
One-to-Many (Each department can have multiple employees, but each employee belongs to
only one department)

 Employees. Department ID (Many) relates to Departments.DepartmentID (One)

Now, let's enter some sample records:

Employees Table:

EmployeeID FirstName LastName DateOfBirth DepartmentID


1 alyaan Xyz 17.01.2000 1
Xyz 17.01.2001
2 Hasnain 2
Xyz 17.01.2002
3 Saqib 1
Xyz 17.01.2003
4 Aqib 3
Xyz 17.01.2004
5 Ubaid 2

Departments Table:

DepartmentID DepartmentName ManagerName Location Budget


1 Sales Shahzaib Islamabad 200,000
2 Marketing Ubaid Karachi 150,000
3 HR Moheen Lahore 100,000

Now, for designing a query, let's say we want to retrieve the list of employees who are
born after 1990 and work in the Sales department:

Query of above Table:


SELECT Employees. First Name, Employees.LastName, Employees.DateOfBirth,
Departments.DepartmentName FROM Employees INNER JOIN Departments ON
Employees.DepartmentID = Departments.DepartmentID WHERE Employees.DateOfBirth
> #2000-01-17# AND Departments.DepartmentName = 'Sales';

This query will return the First Name, Last Name, DateOfBirth of employees who are
born after 2000 and work in the Sales department.
HSSC Part-II
C++ Practical

Practical 1:
Program using: cin, cout, escape sequences, setw

Solution: Below is a simple C++ program that utilizes cin, cout, escape sequences,
and setw to display formatted output.

 Standard input output stream (cin, cout)


#include <iostream>
using namespace std;
int main( ) {
int age;
cout << "Enter your age: ";
cin >> age;
cout << "Your age is: " << age << endl;
}

 Escape Sequence
#include <iostream>

using namespace std;

int main()

cout<<"\'C\'\t\'L\'\t\'i\'\t\'n\'\t\'i\'\t\'c\'\n";

cout<<"\"Electronic\"\n";

Output
 setw manipulator
#include <iostream>
#include <iomanip>
Usingnamespace std;
int main () {
cout << std::setw(5);
cout <<123<< std::endl;
return 0;
}
Output:

Practical 2: Comparing numbers in C++


if(a==b)
{
returntrue;
}
else
{
returnfalse;
}
Program:
#include <iostream>
int a = 15;

int main()
{
if (3 < a < 10)
{
std::cout << "Yes" << std::endl;
}
else
{
std::cout << "No" << std::endl;
}

return 0;
}
The mathematical expression 3 < a < 15 means “3 is less than a and a is less
than 15.”
Practical 3: Reading a number and find out whether it is prime or
composite.

#include <iostream>
using namespace std;

int main() {
int number;
bool isPrime = true;

// Input number from the user


cout << "Enter a positive integer: ";
cin >> number;

// Check if the number is less than or equal to 1


if (number <= 1) {
cout << "The number is neither prime nor composite." << endl;
return 0;
}

// Check if the number is divisible by any number other than 1 and itself
for (int i = 2; i <= number / 2; ++i) {
if (number % i == 0) {
isPrime = false;
break;
}
}

// Output the result


if (isPrime)
cout << number << " is a prime number." << endl;
else
cout << number << " is a composite number." << endl;

return 0;
}
Practical 4: Generating and summing simple series in C++.
Program:
#include <iostream>
using namespace std;

int main() {
int n;
double sum = 0.0;

// Input the number of terms in the series


cout << "Enter the number of terms in the series: ";
cin >> n;

// Generate and sum the series


for (int i = 1; i <= n; ++i) {
sum += 1.0 / i; // Add 1/i to the sum
}

// Output the sum of the series


cout << "Sum of the series: " << sum << endl;

return 0;
}
Output:
Enter the number of terms in the series: 5
Sum of the series: 2.28333

Practical 5: Reversing a given number in C++


#include <iostream>
using namespace std;

int main() {
int number, reversedNumber = 0, remainder;

// Input the number from the user


cout << "Enter a number: ";
cin >> number;

// Reverse the number


while (number != 0) {
remainder = number % 10; // Extract the last digit
reversedNumber = reversedNumber * 10 + remainder; // Append the digit to
the reversed number
number /= 10; // Remove the last digit from the number
}

// Output the reversed number


cout << "Reversed number: " << reversedNumber << endl;

return 0;
}
Output:
If you run the provided C++ program and input a number, let's say 123, the program will output
the reversed number, which will be 321.
Here's the output when you input 123:
Enter a number: 123
Reversed number: 321

Practical 6: Finding out a specific day of a week for a given


data using function in C++
#include <iostream>
using namespace std;

string findDayOfWeek(int year, int month, int day) {


// Months January and February are counted as months 13 and 14 of the previous
year
if (month < 3) {
month += 12;
year--;
}

int h = (day + ((13 * (month + 1)) / 5) + year + (year / 4) - (year / 100) + (year /
400)) % 7;

// Array to store the day names


string days[] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday"};

// Return the day of the week


return days[h];
}
int main() {
int year, month, day;

// Input date from the user


cout << "Enter the year: ";
cin >> year;
cout << "Enter the month (1-12): ";
cin >> month;
cout << "Enter the day of the month: ";
cin >> day;

// Call the function to find the day of the week


string dayOfWeek = findDayOfWeek(year, month, day);
// Output the day of the week
cout << "The day of the week for " << month << "/" << day << "/" << year << " is: " <<
dayOfWeek << endl;
return 0;
}

Output:
Enter the year: 2024
Enter the month (1-12): 4
Enter the day of the month: 1
The day of the week for 4/1/2024 is: Monday

Practical 7: Sum two and/or three numbers of different data


types in C++
Program:
#include <iostream>
using namespace std;

int main() {
int num1;
double num2;
float num3;

// Input three numbers of different data types


cout << "Enter an integer number: ";
cin >> num1;
cout << "Enter a double number: ";
cin >> num2;
cout << "Enter a float number: ";
cin >> num3;

// Sum the numbers


double sumTwo = num1 + num2;
double sumThree = num1 + num2 + num3;

// Output the sums


cout << "Sum of the integer and double numbers: " << sumTwo << endl;
cout << "Sum of all three numbers: " << sumThree << endl;

return 0;
}
Output:
Enter an integer number: 5
Enter a double number: 3.5
Enter a float number: 2.1
Sum of the integer and double numbers: 8.5
Sum of all three numbers: 10.6

Practical 8: Display the address and the value of a variable


using pointer in C++
Program:
#include <iostream>
using namespace std;

int main() {
int number = 10;
int *ptr = &number; // Pointer pointing to the address of 'number'

// Displaying the address of the variable


cout << "Address of the variable: " << &number << endl;

// Displaying the value of the variable


cout << "Value of the variable: " << number << endl;

// Displaying the address using pointer


cout << "Address using pointer: " << ptr << endl;
// Displaying the value using pointer
cout << "Value using pointer: " << *ptr << endl;

return 0;
}
Output:
Address of the variable: 0x7ffd8889f76c
Value of the variable: 10
Address using pointer: 0x7ffd8889f76c
Value using pointer: 10

Practical 9: Create and display student object with data


members as name, age, and class etc in C++.
Program:
#include <iostream>
#include <string>
using namespace std;

// Define a class named Student


class Student {
public:
// Data members
string name;
int age;
string className;

// Member function to display student details


void displayDetails() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Class: " << className << endl;
}
};

int main() {
// Create an object of the Student class
Student student1;

// Assign values to the data members


student1.name = "John";
student1.age = 20;
student1.className = "12th Grade";

// Display student details


cout << "Student Details:" << endl;
student1.displayDetails();

return 0;
}

Output:
Student Details:
Name: Samiullah
Age: 20
Class: 12th Grade

Practical 10: Create and read a data file in C++


Program:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
// Create a file stream object
ofstream outFile;

// Open the file in write mode


outFile.open("data.txt");

// Check if the file is successfully opened


if (!outFile.is_open()) {
cerr << "Error: Unable to open the file." << endl;
return 1; // Exit with error
}

// Write data to the file


outFile << "Hello, this is a sample data file.\n";
outFile << "It contains some text data.\n";
outFile << "You can read this data from another program.\n";
// Close the file
outFile.close();

// Open the file in read mode


ifstream inFile("data.txt");

// Check if the file is successfully opened


if (!inFile.is_open()) {
cerr << "Error: Unable to open the file." << endl;
return 1; // Exit with error
}

// Read and display the data from the file


cout << "Contents of the file:" << endl;
string line;
while (getline(inFile, line)) {
cout << line << endl;
}

// Close the file


inFile.close();

return 0;
}
Output:
Contents of the file:
Hello, this is a sample data file.
It contains some text data.
You can read this data from another program.

End

You might also like