The Site is under maintenance!..Test link

Assignment6

String Operations

String Operations

Answer:

Col 50 Row 50
Col 50 Row 70
Col 25 Row 50

                            

Answer:

Show the answer.
11:20
12:30
13:45                    

Answer:

Show the answer.
10x15x6
11x16x6
10x16x11
                            

Answer:

Show the answer.
struct Pixels
{ 
        int color, style;
}; 

void showPoint(Pixels P)
{
        cout << P.color << P.style << endl;
}

int main()
{ 
        Pixels Point1 = {5, 3} ;
        showPoint(Point1); 
        Pixels Point2 = Point1; 
        Point1.color += 2; 
        showPoint(Point2);

        return 0;
}
                

Answer:

#include 
using namespace std;

// Structure to represent a complex number
struct Complex {
    double real;
    double imag;
};

// Function to add two complex numbers
Complex add(Complex a, Complex b) {
    return {a.real + b.real, a.imag + b.imag};
}

// Function to subtract two complex numbers
Complex subtract(Complex a, Complex b) {
    return {a.real - b.real, a.imag - b.imag};
}

// Function to multiply two complex numbers
Complex multiply(Complex a, Complex b) {
    return {
        a.real * b.real - a.imag * b.imag,
        a.real * b.imag + a.imag * b.real
    };
}

// Function to divide two complex numbers
Complex divide(Complex a, Complex b) {
    double denominator = b.real * b.real + b.imag * b.imag;
    return {
        (a.real * b.real + a.imag * b.imag) / denominator,
        (a.imag * b.real - a.real * b.imag) / denominator
    };
}

// Function to print a complex number
void printComplex(Complex c) {
    cout << c.real;
    if (c.imag >= 0)
        cout << " + " << c.imag << "i";
    else
        cout << " - " << -c.imag << "i";
    cout << endl;
}

// Main function to demonstrate the operations
int main() {
    Complex num1 = {3, 4};
    Complex num2 = {1, 2};

    cout << "Number 1: ";
    printComplex(num1);

    cout << "Number 2: ";
    printComplex(num2);

    cout << "\nAddition: ";
    printComplex(add(num1, num2));

    cout << "Subtraction: ";
    printComplex(subtract(num1, num2));

    cout << "Multiplication: ";
    printComplex(multiply(num1, num2));

    cout << "Division: ";
    printComplex(divide(num1, num2));

    return 0;
}

                

Answer:

#include 
#include 
using namespace std;

// Structure to store student details
struct Student {
    int rollno;
    string name;
    int marks[3];
};

// Function to check if a student has failed in more than one subject
bool hasFailedMoreThanOneSubject(Student student) {
    int failCount = 0;
    for (int i = 0; i < 3; i++) {
        if (student.marks[i] < 40) // Assuming passing marks is 40
            failCount++;
    }
    return failCount > 1;
}

// Main function
int main() {
    const int studentCount = 25;
    Student students[studentCount];

    // Input details for 25 students
    for (int i = 0; i < studentCount; i++) {
        cout << "Enter details for student " << i + 1 << ":\n";
        cout << "Roll No: ";
        cin >> students[i].rollno;
        cin.ignore(); // To consume newline character left in the input buffer
        cout << "Name: ";
        getline(cin, students[i].name);
        cout << "Marks in three subjects: ";
        for (int j = 0; j < 3; j++) {
            cin >> students[i].marks[j];
        }
        cout << endl;
    }

    // Display students who failed in more than one subject
    cout << "\nStudents who failed in more than one subject:\n";
    for (int i = 0; i < studentCount; i++) {
        if (hasFailedMoreThanOneSubject(students[i])) {
            cout << "Roll No: " << students[i].rollno 
                 << ", Name: " << students[i].name << endl;
        }
    }

    return 0;
}