Wednesday, October 14, 2020

NPTEL INTRODUCTION TO PROGRAMMING IN C WEEK 4 ANSWERS (JUL-DEC 2020)

 Question 1:

#include<stdio.h>


int main()

{

int arr1[100], arr2[100];

int n1,n2;

int check = 1;

int i;

  int k;

scanf("%d",&n1);

for( i = 0; i < n1; i++)

scanf("%d",&arr1[i]);


scanf("%d",&n2);

for( i = 0; i < n2; i++ )

scanf("%d",&arr2[i]);


for(i = 0; i < n1; i++)//sorting arr1.

{

for(int j = i; j < n1; j++)

{

if(arr1[j]>arr1[i])

{

int temp = arr1[i];

arr1[i] = arr1[j];

arr1[j] = temp;

}

}

}


for (int k = 0; k < n1; k++)//comparing arr1 and arr2.

{

check = 1;

for(i = 0; i < n2; i++)

{

if(arr1[k] == arr2[i])

{

check = 0;

break;

}

}

if(check == 1)

{

printf("%d",arr1[k] );

break;

}


}

if(check == 0)

printf("0");

return 0;


Question 2:

#include<stdio.h>


int main()

{

int arr[100];

int n1,n2;

int counter = 0;

int i;

scanf("%d",&n1);

for( i = 0; i < n1; i++)

scanf("%d",&arr[i]);



for(i = 0; i < n1; i++)

{

for(int j = i; j < n1; j++)

{

if(arr[j]>arr[i])

{

int temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

}


for( i = 0; i < n1; i++)

{

if(arr[i] != arr[i+1])

counter++;

}

printf("%d",counter );


return 0;


}

Question 3:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>



char* replaceWord(const char* s, const char* oldW,

                  const char* newW)

{

    char* result;

    int i, cnt = 0;

    int newWlen = strlen(newW);

    int oldWlen = strlen(oldW);



    for (i = 0; s[i] != '\0'; i++) {

        if (strstr(&s[i], oldW) == &s[i]) {

            cnt++;



            i += oldWlen - 1;

        }

    }



    result = (char*)malloc(i + cnt * (newWlen - oldWlen) + 1);


    i = 0;

    while (*s) {


        if (strstr(s, oldW) == s) {

            strcpy(&result[i], newW);

            i += newWlen;

            s += oldWlen;

        }

        else

            result[i++] = *s++;

    }


    result[i] = '\0';

    return result;

}



int main()

{

    char str[100];

    char c[2];

    char d[10];


    char* result = NULL;


    scanf("%s",str);

    scanf("%s",c);

    scanf("%s",d);


    result = replaceWord(str, c, d);

    printf("%s", result);


    free(result);

    return 0;

}


Tuesday, October 13, 2020

NPTEL PROGRAMMING IN C++ ASSIGNMENT WEEK 4 ANSWERS 2020(JUL-DEC)

 Question 1 :

#include <iostream>

using namespace std;


class B;             // LINE-1


class A {

    int a_ = 0;

public:

    A(int x) : a_(x) { }

    int addB(B&);

    int subtractB(B&);

};


class B {

    int b_ = 5;

public:

    friend class A;         // LINE-2

};


Question 2:

Complex operator *(const Complex &c) { // LINE-1

        int x, y;

        x = re*(c.re) - im*(c.im);            // LINE-2

        y = im*(c.re) + (c.im)*re;            // LINE-3

        Complex t1(x, y);

        return t1;

    }


Question 3:

        if(data == m1.data) m.data = 1;    // LINE-1

            return m;

    }

};


void fun(myClass m) { // LINE-2


Question 4:

#include <iostream>

using namespace std;


class myClass {

    int data;

    static myClass *t;        // LINE-1 Complete the declaration

    myClass(int x) : data(x) { }

public:

    static myClass *create(int x) {    // LINE-2 Mention return type of the function

        if (!t)

            t = new myClass(x);       // LINE-3 Allocate memory towards object t

            return t;

    }



Saturday, October 10, 2020

NPTEL PROGRAMMING IN JAVA WEEK 4 ANSWERS (JUL-DEC 2020)

 

QUESTION 1:


import java.io.*;
import java.util.*;
import static java.lang.System.*;

QUESTION 2:


// Create an object of Calendar class. 
java.util.Calendar current ;

// Use getInstance() method to initialize the Calendar object.
current = java.util.Calendar.getInstance();

// Initialize the int variable year with the current year
year = current.get(current.YEAR);

QUESTION 3:


interface ExtraLarge{
String extra = "This is extra-large";
void display();
}

class Large {
    public void Print() {
        System.out.println("This is large");
    }
}

class Medium extends Large {
    public void Print() {
       super.Print();  
        System.out.println("This is medium");
    }
}
class Small extends Medium {
    public void Print() {
        super.Print();  
        System.out.println("This is small");
    }
  }


class Question43 implements ExtraLarge{
    public static void main(String[] args) {
        Small s = new Small();
        s.Print();
  Question43 q = new Question43();
  q.display();
    }
  public void display(){
    System.out.println(extra);
  }
}


QUESTION 4:


// Call show() of First interface.
First.super.show();
// Call show() of Second interface.
Second.super.show();

QUESTION 5:


// Interface ShapeX is created
interface ShapeX {
 public String base = "This is Shape1";
 public void display1();
}

// Interface ShapeY is created which extends ShapeX
interface ShapeY extends ShapeX {
 public String base = "This is Shape2";
 public void display2();
}

// Class ShapeG is created which implements ShapeY
class ShapeG implements ShapeY {
 public String base = "This is Shape3";
 //Overriding method in ShapeX interface
 public void display1() {
  System.out.println("Circle: " + ShapeX.base);
 }
 // Override method in ShapeY interface
  public void display2(){
  System.out.println("Circle: " + ShapeY.base);}
}

Tuesday, October 6, 2020

NPTEL PROGRAMMING IN C++ ASSIGNMENT WEEK 3 ANSWERS 2020(JUL-DEC) || CODE LINK IN THE COMMENTS

 Question 1:

 triangle(int b, int h) : _base(&b), _height(&h) { } // Line-1


    // LINE-1: Complete Constructor definition


    ~triangle() {

        _base = 0; // Line-2

        _height = 0;// LINE-2: Complete destructor to delete both data pointers


    }

    double area();

};


double triangle::area() {  // LINE-3: Complete function header

Question 2:

 mutable int _sem;        // LINE-1

public:

    Student(int roll, string name, int sem)

        : _roll(roll), _name(name), _sem(sem) { }


    void promote() const { // LINE-2

        _sem++;

    }


    void display() const{ // LINE-3

Question 3:

#include <iostream>

#include <string>

using namespace std;


class Complex {

    const int _r, _i;


public:

    Complex() : _r(0), _i(0){ }                       // LINE-1


    Complex(int r) : _r(r),_i(0) { }                  // LINE-2


    Complex(int r, int i) : _r(r), _i(i) { }           //          


Question 4 :

integer objA;  // LINE-1: Invoke Default Constructor


    integer objB(val);  // LINE-2: Invoke Parameterized Constructor


    integer objC = objB;  // LINE-3: Invoke Copy Constructor

Monday, October 5, 2020

NPTEL PROGRAMMING IN JAVA WEEK 3 ANSWERS (JUL-DEC 2020)


QUESTION 1:

if (n<=1) 
            return (1-n); 
        return fib(n - 1) + fib(n - 2); 

QUESTION 2:

class Point{
   double x,y;
  
   public double distance(Point p1, Point p2)
                {
                  
                  double root=(p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
                  root=Math.sqrt(root);
                  System.out.print(root);
                  return root;
                }
}

QUESTION 3:


//Create a derived class constructor which can call the one parametrized constructor of the base class
double height;
Test1(double l, double h){
  super(l);
  this.length=l;
  this.height=h;
}

//Create a derived class constructor which can call the two parametrized constructor of the base class
Test1(double l, double b, double h){
  super(l,b);
  this.length=l;
  this.breadth=b;
  this.height=h;
}
  
  

//Override the method calculate() in the derived class to find the volume of a shape instead of finding the area of a shape

double calculate(){
  
  return length*breadth*height;}

QUESTION 4:


QuestionScope a= new QuestionScope();
System.out.println(a.sum(n1,n2));
System.out.print(QuestionScope.multiply(n1,n2));

QUESTION 5:


static void swap(Question obj)
        {
          int temp;
          temp=obj.e1;
          obj.e1=obj.e2;
          obj.e2=temp;
        }

Wednesday, September 30, 2020

NPTEL INTRODUCTION TO PROGRAMMING IN C WEEK 3 ANSWERS (JUL-DEC 2020)

 Question 1:

#include<stdio.h>


int find_odd(int k)

{

  int num;

  int counter = 0;

  int check = 0;

  

  while(num != -1)

  {

    scanf("%d",&num);

    if(num%2!=0)

    {

      counter++;

      if(counter == k)

      {

        printf("%d",num);

        check = 1;

      }

    }

    

       

  }

   if((counter != k) && (check == 0))

      printf("-1");


  return 0;

}



int main()

{

  int k;

  scanf("%d",&k);

  find_odd(k);

  return 0;

}

Question 2:

#include<stdio.h>


int main()

{

  float num1,num2;

  float m_avg;

  

  scanf("%f",&num1);

  

  while(num1 != -1)

  {

    num2 = num1;

    scanf("%f",&num1);

      if(num1!=-1)

        { m_avg = (num1+num2)/2;

    printf("%0.1f ",m_avg);

        }

    

  }

  return 0;

}

    

Question 3:


#include<stdio.h>


int main()

{

  int n;

  scanf("%d",&n);

  int fac = 1;

  

  for(int i = 1; i<n; i++)

  {

    fac = fac*i; 

    if(fac <= n)

     {

        printf("%d ",fac);

      }

    else 

      break;

  }

  return 0;

  

}


Thursday, September 24, 2020

NPTEL PROGRAMMING IN JAVA WEEK 2 ANSWERS (JUL-DEC 2020)

 Question 1:

// Create an object of class Student


// Call 'print()' method of class Student 


// Create an object of class School


// Call 'print()' method of class School


Student obj = new Student();


obj.print();


School obj_1 = new School();


obj_1.print();


 Question 2:

// Create an object of class Printer


// Call 'print()' methods for desired output


Printer obj = new Printer();


obj.print("Hi! I am class STUDENT");


obj.print();


 Question 3:

// Define a method named 'studentMethod()' in class Question


// Call the method named 'print()' in class Question


void studentMethod(){

  

  Question23 obj = new Question23();

  print(obj);

}



 Question 4:

class Answer{

Answer(){

System.out.println("You got nothing.");

}

Answer(int marks, String type){

      this();

System.out.print("You got "+marks+" for an "+type);

}

}


 Question 5:

//Declare variable with name 'nptel', 'space' and 'java' and proper datatype.


//Initialize the variables with proper input


String nptel = "NPTEL", space = " ", java = "JAVA";


Wednesday, September 23, 2020

NPTEL INTRODUCTION TO PROGRAMMING IN C WEEK 2 ANSWERS (JUL-DEC 2020)

Question 1:

#include<stdio.h>

int main()
{
  int arr[50][50];
  int n;
  int upper = 1, lower = 1;
  scanf("%d",&n);
  
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<n; j++)
      scanf("%d",&arr[i][j]);
  }
  
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<n; j++)
    {
      if(i>j&&arr[i][j]!=0)
      {
        upper = 0;
      }
      
      else if(j>i&&arr[i][j]!=0)
      {
        lower = 0;
      }
     } 
  }
  
 if(upper == 1 && lower == 0)
   printf("1");
 else if(upper == 0 && lower == 1)
   printf("-1");
 else if (upper == 1 && lower == 1)
   printf("2");
 else 
   printf("0");
  
  return 0;
}


Question 2:


#include<stdio.h>

int main()
{
  int n;
  int arr[100];
  int i=0;
  
  
  while(n!=-1)
  {
    scanf("%d",&n);
    arr[i]=n;
    i++;
  }
  
  for(int j=0; j<i; j++)
    for(int k=j; k<i; k++)
    if(arr[j]<arr[k])
  {
    int temp;
    temp = arr[j];
    arr[j] = arr[k];
    arr[k] = temp;
  }
  
  int distinct=0;
  
  for(int j=0; j<i-1; j++)
  {
    if(arr[j]!=arr[j+1])
      distinct++;
  }
  
  if(distinct>=3)
    printf("1");
  else 
    printf("0");
}


Question 3:


#include<stdio.h>

int main()
{
  int n;
  int arr[100];
  int i=0;
  
  
  while(n!=-1)
  {
    scanf("%d",&n);
    arr[i]=n;
    i++;
  }
  
  for(int j=0; j<i; j++)
    for(int k=j; k<i; k++)
    if(arr[j]<arr[k])
  {
    int temp;
    temp = arr[j];
    arr[j] = arr[k];
    arr[k] = temp;
  }
  
  int distinct=0;
  
  for(int j=0; j<i-1; j++)
  {
    if(arr[j]!=arr[j+1]&&arr[j+1]!=-1)
    {
      distinct=arr[j+1];
      printf("%d",distinct);
      break;
    }
  }
  
  if(distinct==0)
    printf("0");
    
}

NPTEL PROGRAMMING IN C++ ASSIGNMENT WEEK 2 ANSWERS 2020(JUL-DEC)

 Question 1:

Complex operator*(Complex &p1, Complex &p2) { // LINE-1
    struct Complex p3 = { 0, 0 };
    p3.x = (p1.x)*(p2.x) - (p1.y)*(p2.y); // LINE-2
    p3.y = (p1.x)*(p2.y) + (p1.y)*(p2.x); // LINE-3
    return p3;
}


Question 2:

#include <iostream>
#include <string>
using namespace std;
void print(string a, string b = "Anyone") { // LINE-1


Question 3:

#include <iostream>
using namespace std;
int Double(int a) { // LINE-1
    return a*2;   // LINE-2
}


Qu
estion 4:

int main() {
    int *p;
    int arr[10];
  p =  arr;// LINE-1
    
    process(p);
    
        
    return 0;
}


Monday, September 14, 2020

Programming in Java WEEK 1 NPTEL(JULY - DEC 2020) ASSIGNMNET SOL.

Question 1: 

 
if(radius>0)
       {
perimeter = 2*Math.PI*radius;
    area = (Math.PI)*radius*radius;
          System.out.println(perimeter);
          System.out.print(area);
       }

else 
      System.out.print("please enter non zero positive number");


Question 2:


//Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.

if(x>y)
        {
          if(x>z)
            System.out.print(x);
          else 
            System.out.print(z);
        }

else 
        {
          if(y>z)
            System.out.print(y);
          else
            System.out.print(z);
        }

Question 3:


//Use for or while loop do the operation

  for(int i = 0, j = 0; i<n; i++, j=j+2)
      {
        if(j%3==0)
          sum = sum + j;
      }
  System.out.print(sum);
        

Question 4:


//Use while loop check the number is Armstrong or not.
//store the output(1 or 0) in result variable.
int sum = 0;
int n1 = n;
int counter = 0;
int[] arr = new int[100];

while(n>0)
        {
          int rem = n%10;
          arr[counter] = rem;
          n = n/10;
          counter++;
        }

for(int i=0; i<counter; i++)
        {
          int l = 1;
          for(int j=1; j<=counter; j++)
          {
            l=l*arr[i];
          }
          sum = sum + l;
        }
            

if(sum == n1)
          result = 1;
else 
          result = 0;

System.out.print(result);

          

Question 5:


//Initialize maximum element as first element of the array.  
   //Traverse array elements to get the current max.
   //Store the highest mark in the variable result.
   //Store average mark in avgMarks.
int largest;
int sum = 0;
float avg;
for(i=0;i<arr.length;i++)
  {
        for(int j = i; j<arr.length; j++)
                  if(arr[i]<arr[j])
                {
                  int temp = arr[i];
                  arr[i] = arr[j];
                  arr[j] = temp;
                }
    } 

largest = arr[0];

for(i=0;i<arr.length;i++)
  {
        sum = sum + arr[i];
  } 
avg = sum/arr.length;
System.out.println(largest);
System.out.print(avg);

Programming in C++ WEEK 1 NPTEL(JULY-DEC 2020) ASSIGNMNET SOL.

 Question 1 :

stack<char> s;    // LINE-1    



    for (int i = 0; i < strlen(str); i++)


        s.push(str[i]);    // LINE-2


Question 2 :

bool StrCmp(string s1, string s2) {


    if (s1.length()>s2.length() || s1.length()<s2.length())    // LINE-1

    

        return 1;    // LINE-2

    else

        return 0;    // LINE-3

}


Question 3 :

typedef void (*Fun_Ptr)(int,int); // LINE-1


Fun_Ptr fp = &add; // LINE-2

Sunday, September 13, 2020

Introduction to Programming in C week 1 NPTEL(JULY - DEC 2020) assignmnet solution

 Question 1 :

#include<stdio.h>


void  main()

{

  int arr[4];

  for(int i=0; i<3; i++)

    scanf("%d",&arr[i]);    //To take input.

  

  int sum = arr[0] + arr[1];

  

  if(sum>arr[2]) //if statement to check wether third number is smaller than the sum of

    printf("1"); //first two.

  else 

    printf("0");

}



Question 2 :

#include<stdio.h>


void main()

{

  int m,n;

  scanf("%d",&m);

  scanf("%d",&n);

  

  int rem = m%n;  //% is used to find the remainder.

  

  if(rem==1)

    printf("1");

  else 

    printf("0");

  

}


Question 3:

#include<stdio.h>


void main()

{

  float arr[4];

  

  for(int i=0; i<3; i++)

    scanf("%f",&arr[i]);

  

  //To check wether the triplet is strictly increasing or decreasing or none.

  

  if(arr[0]>arr[1]&&arr[1]>arr[2])

    printf("1");

  else if(arr[2]>arr[1]&&arr[1]>arr[0])

    printf("1");

  else

    printf("0");

}

  

Saturday, August 1, 2020

GTA San Andreas 2.00 Full Apk + Data for Android 2020

Five years ago, Carl Johnson escaped from the pressures of life in Los Santos, San Andreas, a city tearing itself apart with gang trouble, drugs and corruption. Where filmstars and millionaires do their best to avoid the dealers and gangbangers.


Now, it’s the early 90’s. Carl’s got to go home. His mother has been murdered, his family has fallen apart and his childhood friends are all heading towards disaster.
On his return to the neighborhood, a couple of corrupt cops frame him for homicide. CJ is forced on a journey that takes him across the entire state of San Andreas, to save his family and to take control of the streets.
Rockstar Games brings its biggest release to mobile yet with a vast open-world covering the state of San Andreas and its three major cities – Los Santos, San Fierro and Las Venturas – with enhanced visual fidelity and over 70 hours of gameplay.
Grand Theft Auto: San Andreas features:
  • Remastered, high-resolution graphics built specifically for mobile including lighting enhancements, an enriched color palette and improved character models.
  • Cloud save support for playing across all your mobile devices for Rockstar Social Club Members.
  • Dual analog stick controls for full camera and movement control.
  • Three different control schemes and customizable controls with contextual options to display buttons only when you need them.
  • Compatible with the MoGa Wireless Game Controllers and select Bluetooth and USB gamepads.
  • Integrated with Immersion tactile effects.
  • Tailor your visual experience with adjustable graphic settings.
Languages Supported: English, French, Italian, German, Spanish, Russian and Japanese.
For optimal performance, we recommend re-booting your device after downloading and closing other applications when playing Grand Theft Auto: San Andreas.
For information about supported devices and compatibility, please see:
http://support.rockstargames.com/hc/en-us/sections/200251868-San-Andreas-Mobile-Support
Mobile Version developed by War Drum Studios
www.wardrumstudios.com

Download link :

                           Download APK file


                         Download DATA file

Tuesday, July 28, 2020

Solving your first problem in C++ on CodeChef

Problem Name : Life, the Universe, and Everything

How to solve this question?


In this question they telling us to take the input of a number and display that number, repeat this proedure till we encounter number 42. After that we need to stop.

Solution :


#include <iostream>
using namespace std;

int main() {
// your code goes here
int number;
cin>>number;
while(number!=42)
{
    cout<<number<<endl;
    cin>>number;
}
return 0;
}




Sunday, July 26, 2020

Introduction to Programming in C week 0 assignment(jul-dec 2020)

Hello everyone! solution of Introduction to Programming in C week 0 assignment are given below.

Question 1 : 


#include<stdio.h>

int main()
{
  printf("Hello C");
  return 0;
}

Question 2 :


#include<stdio.h>

int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  int avg = (a+b)/2;
  printf("%d",avg);
  return 0;
}



Tuesday, April 7, 2020

PROGRAMMING IN JAVA WEEK 10

QUESTION 1:

import java.*;
import java.sql.*;

QUESTION 2:

// Open a connection and check connection status
conn = DriverManager.getConnection(DB_URL);
if(conn.isClosed())
  System.out.print("false");
else
  System.out.print("true");

QUESTION 3:

import java.sql.*;
import java.util.Scanner;
import java.lang.*;

public class Question103 {
    public static void main(String args[]) {
        try {
              Connection conn = null;
              Statement stmt = null;
              String DB_URL = "jdbc:sqlite:/tempfs/db";
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
            conn = DriverManager.getConnection(DB_URL);
              conn.close();
              System.out.print(conn.isClosed());
        }
       catch(Exception e){ System.out.println(e);}
    }
}


QUESTION 4:

// The statement containing SQL command to create table "players"
String sql = "CREATE TABLE PLAYERS "+
  "(UID INT, "+
  "First_Name VARCHAR(45), "+
  "Last_Name VARCHAR(45), "+
  "Age INT, "+
  " PRIMARY KEY(UID))";

// Execute the statement containing SQL command below this comment
stmt.executeUpdate(sql);


QUESTION 5:

// Write the SQL command to rename a table
String str = "alter table PLAYERS rename to SPORTS";

// Execute the SQL command
stmt.executeUpdate(str);


Monday, March 23, 2020

WEEK 8

QUESTION 1:


// Declare a user-defined exception
class NegativeValException : public exception {     // LINE-1
public:
    virtual const char* what() const throw() {
        return "Negative value";
    }
};

// Declare a user-defined exception
class ZeroValException : public exception {         // LINE-2
public:
    virtual const char* what() const throw() {
        return "Zero";
    }
};

int main() {
    int i;
    cin >> i;
   
    try {
        if (i < 0)
            // Throw the exception object
            throw NegativeValException();                               // LINE-3

        else if (i == 0)
            // Throw the exception object
            throw ZeroValException();                               // LINE-4

QUESTION 2:


template <class T, int n>                    // LINE-1
class container {
    T arr[n];                // LINE-2

    int i;
public:
    container() : i(-1) { }

    void operator=(char data) {// LINE-3

QUESTION 3:


template <class T, int n>  // LINE-1

void mysequence<T,n>::setVal(int i, T value) {  // LINE-2

    items[i] = value;
}

template <class T, int n>   // LINE-3

T mysequence<T,n>::getVal(int i) {  // LINE-4

    return items[i];
}

Wednesday, March 18, 2020

WEEK 7 ASSIGNMENT SOLUTION

GUYS I KNOW I WAS SUPER INCONSISTENT AND LATE IN UPLOADING THE SOLUTIONS BUT I WAS HAVING A BUSY TIME IN PAST FEW WEEKS(COLLEGE WORK ) , I AM NOT GIVING ANY EXCUSES BUT JUST LETTING YOU ALL GUYS KNOW WHAT WAS THE REASON DUE TO WHICH I AM UPLOADING VIDEOS SO LATE. AND THANKS FOR WATCHING MY STUFF. 

QUESTION 1:

import java.util.*;
public class Question1{
        public static void main (String[] args){

//Write the appropriate code to read the 3 integer values and find their sum.
 int a,b=0,sum=0;
          Scanner i = new Scanner(System.in);
          for(a=0; a<3; a++)
          {
            b=i.nextInt();
            sum=sum+b;
          }

QUESTION 2:


try{InputStreamReader r=new InputStreamReader(System.in); 
   BufferedReader br=new BufferedReader(r); 
   String number=br.readLine(); 
   int x = Integer.parseInt(number);
   System.out.print(x*x);
   }
catch(Exception e){
  System.out.print("Please enter valid data");
}

QUESTION 3:


// Complete the code to get specific indexed byte value and its corresponding char value.
String str=new String(barr,n,1);
System.out.println(barr[n]);
System.out.print(str);
}

QUESTION 4:


//Write your code here to count the number of vowels in the string "s1"
for(int i=0;i<s1.length();i++){
  char s=s1.charAt(i);
  if(s=='a'||s=='A'||s=='e'||s=='E'||s=='i'||s=='I'||s=='o'||s=='O'||s=='u'|| s=='U')
  {
    c=c+1;
  }
}

QUESTION 5:


//Replace the char in string "s1" with the char 'a' at index "n"  and print the modified string
byte[] barr=s1.getBytes();
byte b1=(byte) c;
barr[n]=b1;
System.out.print(new String(barr));
}

Monday, March 16, 2020

WEEK 7 ASSIGNMENT SOLUTION

QUESTION 1:


Container& operator =(int val) {      // LINE-1

        this->arr[++i] = val;
        return *this;
    }

    operator int()  {      // LINE-2

        return arr[i--];
    }
};


QUESTION 2:


    virtual void print(int i)=0;          // LINE-1
};

class derived1 : public base{ // LINE-2
public:
    void print(int i) { cout << i * 1 << " "; }
};

class derived2 : public base { // LINE-3
public:
    void print(int i) { cout << i * 2 << " "; }
};

class derived3 : public base{ // LINE-4

QUESTION 3:


void updateSem(int new_sem) const{             // LINE-1

        student* ptr=const_cast<student*> (this);
      ptr->sem = new_sem;             // LINE-2
    }

    void show() const { 


QUESTION 4:


class derived1 : virtual public base {    // LINE-1
public:
    derived1();
    derived1(int _pr);
};

class derived2 : virtual public base {    // LINE-2
public:
    derived2();
    derived2(int _pr);
};

class dd : public derived2, public derived1 {          // LINE-3

Wednesday, March 11, 2020

WEEK 6 ASSIGNMENT SOLUTION

QUESTION 1:

// Write the appropriate code to extend the Thread class to complete the class Question61.
public class Question61 extends Thread{

public void run()
{
  System.out.print("Thread is Running.");
}

QUESTION 2:

// Create main class Question62 with main() method and appropriate statements in it
public class Question62{
  public static void main(String[] args){
    ThreadRun a = new ThreadRun();
    Thread b = new Thread(a);
    b.start();
  }
}


QUESTION 3:

// Create a class named MyThread and extend/implement the required class/interface

// Define a method in MyThread class to print the output

class MyThread extends B
{
  public void run()
  {
    System.out.print("NPTEL Java");
  }
}

QUESTION 4:

synchronized void print(int n){
   for(int i=1;i<=5;i++){ 
     System.out.println(n*i); 
     try{ 
      Thread.sleep(400); 
     }catch(Exception e){
        System.out.println(e);
     } 
   }
 } 


QUESTION 5:

// Write the necessary code below...
t.setPriority(Thread.MAX_PRIORITY);
t.start();
t.setName("NPTEL");