Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**In Java or C++** Build a system which allows a client to practice multiple cho

ID: 3603569 • Letter: #

Question

**In Java or C++**

Build a system which allows a client to practice multiple choice tests in math. Design and implement a client and server programs over a TCP network socket connection, which will do the following:

Client:

Connect to server

Create new contact by providing <new user> command

And password by providing <psw= password>

Login to the server if he already registered by providing the user name and password

Asking for the math exams

Can redo the exams again

Can show the scores of his tests

Close the connection

Server:

Wait for a client connection.

Store the user name and password of the users

Verify if the user in registered

When a client connection is accepted (if user is registered) send an acknowledgement (a welcome message) as a string of text.

From Questions database, server sends the first test questions plus three possible answers to the client.

Receives the answer from the client. Stores and evaluates the answer. This process is repeated three times.

After that the server sends score to the client and if he like to repeat the test

Store the score of the test for that user

Questions database:

Q1: (A + B)*(A+B)
1. A*A + B*B
2. A*A +A*B + B*B
3. A*A +2*A*B + B*B (correct)

Q2: (A + B)*(A - B)
1. A*A + 2*B*B
2. A*A - B*B (correct)
3. A*A -2*A*B + B*B

Q3: sin(x)*sin(x) + cos(x)*cos(x)
1. 1 (correct)
2. 2
3. 3

Explanation / Answer

server

clint

#include <stdio.h>

#include <sys/socket.h>

#include <stdlib.h>

#include <netinet/in.h>

#include <string.h>

#define PORT 8080

  

int main(int argc, char const *argv[])

{

    struct sockaddr_in address;

    int sock = 0, valread;

    struct sockaddr_in serv_addr;

    char *hello = "Hello from client";

    char buffer[1024] = {0};

    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)

    {

        printf(" Socket creation error ");

        return -1;

    }

  

    memset(&serv_addr, '0', sizeof(serv_addr));

  

    serv_addr.sin_family = AF_INET;

    serv_addr.sin_port = htons(PORT);

      

    // Convert IPv4 and IPv6 addresses from text to binary form

    if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)

    {

        printf(" Invalid address/ Address not supported ");

        return -1;

    }

  

    if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)

    {

        printf(" Connection Failed ");

        return -1;

    }

    send(sock , hello , strlen(hello) , 0 );

    printf("Hello message sent ");

    valread = read( sock , buffer, 1024);

    printf("%s ",buffer );

    return 0;

}