GOA BOARD 2024 PAPER SOLUTION

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Section - A

1. 25

2. 6 – 6 = 0 is pushed on to the stack

3. Insertion sort

4. ios::out

5. A’BC

6. 0.196.45.0

7. Modem

8,9. REFER TO THE NOTES

10. QUEUE

11. IFSTREAM

12,13 REFER TO THE NOTES

14. File transfer protocol

SECTION-B

15. Function 1 is called destructor, and it gets called when the object gets
destroyed/deleted.
Function 2 is called parameterized constructor, and it gets invoked when an
object is created.
Statement to invoke function 2: JOB(8,’a’);

16. 3:5
3:2

17. Node Links:

● Singly Linked List: Each node has a single link that points to the next
node in the sequence.
● Doubly Linked List: Each node has two links, one that points to the next
node and another that points to the previous node, allowing bidirectional
traversal.

Traversal:
● Singly Linked List: Can only be traversed in one direction (from the
head to the end).
● Doubly Linked List: Can be traversed in both directions (from head to
end and from end to head), which makes it more versatile but also
requires more memory per node.

18. REFER TO THE NOTES

19. fin.seekg(25, std::ios::cur);


fout.seekp(-10, std::ios::end);

20. #include <iostream>


#include <fstream>
using namespace std;

int COUNT() {
ifstream file("data.txt");
char ch;
int count = 0;

while (file.get(ch)) { // Read each character


if (ch >= 'A' && ch <= 'Z') { // Check if it's a capital letter
count++;
}
}

file.close();
return count;
}

int main() {
int capitalCount = COUNT();
if (capitalCount != -1) {
cout << "Number of capital letters in the file: " << capitalCount <<
endl;
}
return 0;
}

21. b(a+c)

22,23,24 REFER TO THE NOTES

25. REFER TO THE NOTES


26. #include <iostream>
using namespace std;

class Tourist {
// Private Data Members
int Cno; // Cab number
char Ctype; // City type ('A', 'B', or 'C')
float Perkm; // Per kilometer charge
float Distance; // Distance traveled in kilometers
float Amount; // Total amount (Perkm * Distance)

// Private Member Function


void Assign() {
// Set Perkm based on Ctype
if (Ctype == 'A') {
Perkm = 20;
} else if (Ctype == 'B') {
Perkm = 18;
} else if (Ctype == 'C') {
Perkm = 15;
}
}

public:
// Public Member Function to read data
void readdata() {
cout << "Enter Cab Number: ";
cin >> Cno;
cout << "Enter City Type (A, B, or C): ";
cin >> Ctype;
cout << "Enter Distance traveled (in km): ";
cin >> Distance;

Assign(); // Call Assign function to set Perkm


}

// Public Member Function to display data


void displaydata() {
Amount = Perkm * Distance; // Calculate Amount
cout << "Cab Number: " << Cno << endl;
cout << "City Type: " << Ctype << endl;
cout << "Distance traveled: " << Distance << " km" << endl;
cout << "Charge per km: " << Perkm << endl;
cout << "Total Amount: " << Amount << endl;
}
};

int main() {
Tourist t;
t.readdata(); // Input cab details
t.displaydata(); // Display cab details and amount
return 0;
}

27. i)Multilevel Ineritance


ii)advance,wallarea,colorcode,type.
iii)billing(),pbook(),book(),show()
iv)exterior,paint,bill

30. int IS_SKEWSYM(int A[][50], int n) {


// Loop through the elements of the matrix
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
// Check if A[i][j] is not equal to -A[j][i]
if (A[i][j] != -A[j][i]) {
return 0; // Matrix is not skew-symmetric
}
}
}
return 1; // Matrix is skew-symmetric
}

31. #include <iostream>


using namespace std;

int isNeon(int num) {


int square = num * num;
int sum = 0;

// Sum the digits of the square


while (square > 0) {
sum += square % 10;
square /= 10;
}

// Check if sum of digits equals the original number


return sum == num;
}

int main() {
int number;
cout << "Enter a number: ";
cin >> number;

if (isNeon(number)) {
cout << number << " is a Neon number." << endl;
} else {
cout << number << " is not a Neon number." << endl;
}

return 0;
}

OR
// convert binary to decimal

#include <iostream>
#include <cmath>

using namespace std;

// function prototype
int convert(long long);

int main() {
long long n;
cout << "Enter a binary number: ";
cin >> n;
cout << n << " in binary = " << convert(n) << " in decimal";
return 0;
}

// function definition
int convert(long long n) {
int dec = 0, i = 0, rem;

while (n!=0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}

return dec;
}

32. #include <iostream>


using namespace std;
void removeDuplicates(int A[], int &n) {
if (n == 0 || n == 1) {
return; // Array is already unique if it has 0 or 1 element.
}

int j = 0; // Index for the unique array

// Traverse the array and skip duplicates


for (int i = 0; i < n - 1; i++) {
if (A[i] != A[i + 1]) {
A[j++] = A[i];
}
}
A[j++] = A[n - 1]; // Include the last unique element.

// Update the size of the array


n = j;
}

int main() {
int A[] = {1, 1, 1, 2, 3, 3, 3, 4, 4}; // Example input array
int n = sizeof(A) / sizeof(A[0]);

cout << "Original array: ";


for (int i = 0; i < n; i++) {
cout << A[i] << " ";
}
cout << endl;

removeDuplicates(A, n);

cout << "Array after removing duplicates: ";


for (int i = 0; i < n; i++) {
cout << A[i] << " ";
}
cout << endl;

return 0;
}

OR

#include <iostream>
using namespace std;

void setdifference(int A[], int m, int B[], int n) {


int C[m]; // Array C to store the result
int k = 0; // Index for C array

for (int i = 0; i < m; i++) {


bool found = false;
// Check if A[i] is in B
for (int j = 0; j < n; j++) {
if (A[i] == B[j]) {
found = true;
break;
}
}
// If A[i] is not found in B, add it to C
if (!found) {
C[k++] = A[i];
}
}

// Display elements of C (A - B)
cout << "Array C (A - B): ";
for (int i = 0; i < k; i++) {
cout << C[i] << " ";
}
cout << endl;
}

int main() {
int A[] = {4, 8, 3, 9, 1, 7};
int B[] = {8, 2, 5, 6, 9};
int m = sizeof(A) / sizeof(A[0]);
int n = sizeof(B) / sizeof(B[0]);

setdifference(A, m, B, n);

return 0;
}

33. #include <iostream>


using namespace std;

// Abstract class STUDENT


class STUDENT {
private:
int rollno;

protected:
// Protected show function to display rollno
void show() {
cout << "Roll No: " << rollno << endl;
}

public:
// Parameterized constructor to initialize rollno
STUDENT(int r) : rollno(r) {}
// Making STUDENT an abstract class by defining a virtual function
virtual void dummy() = 0;
};

// Abstract class TEACHER


class TEACHER {
private:
int tcode;

protected:
// Protected show function to display tcode
void show() {
cout << "Teacher Code: " << tcode << endl;
}

public:
// Parameterized constructor to initialize tcode
TEACHER(int t) : tcode(t) {}
// Making TEACHER an abstract class by defining a virtual function
virtual void dummy1() = 0;
};

// Derived class COURSE inheriting from STUDENT and TEACHER


class COURSE : public STUDENT, public TEACHER {
private:
int ccode;

public:
// Parameterized constructor to initialize ccode
COURSE(int r, int t, int c) : STUDENT(r), TEACHER(t), ccode(c) {}

// Overriding show() function to display ccode and also call base class show
functions
void show() {
STUDENT::show();
TEACHER::show();
cout << "Course Code: " << ccode << endl;
}

// Overriding dummy functions to satisfy abstract class requirements


void dummy() {
cout<<"in virtual function";
}
void dummy1()
{
cout<<"in virtual function 2";

};

int main() {
// Creating an object of COURSE and displaying data members
COURSE obj(101, 202, 303);
obj.show();

return 0;
}

Q34) void volunteer_data()


{
volunteers v;
ifstream i,j;
i.open("north.dat");
j.open("south.dat");
oftstream o;
o.open("collect.dat",ios::out | ios::app)
while(i.read((char *)&v,sizeof(v)))
{
if(v.age>18 && v.age<25)
{
o.write((char *)&v,sizeof(v));
}
}
while(j.read((char *)&v,sizeof(v)))
{
if(v.age>18 && v.age<25)
{
o.write((char *)&v,sizeof(v));
}
}
i.close();
j.close();
o.close();
}

Q34 void copy()


or) {
VOTERS v;
ifstream i;
i.open("voters.dat");
ofstream o,p;
o.open("male.dat");
p.open("female.dat");
while(i.read((char *)&v,sizeof(v)))
{
if(v.gender=='m')
{
o.write((char *)&v,sizeof(v));
}
if(v.gender=='f')
{
p.write((char *)&v,sizeof(v));
}
}
i.close();
o.close();
p.close();
}

Q35) Refer to insert and delete functions in linked list programs.

You might also like