Enable contrast version

Tutor profile: Vikas N.

Inactive
Vikas N.
Tutor
Tutor Satisfaction Guarantee

Questions

Subject: Python Programming

TutorMe
Question:

A program that create the 2D list filled with values, then traverse into the list and then displays the index corresponds to the value 1.

Inactive
Vikas N.
Answer:

First, you have to initialize the 2D list with values Like this: #initialize 2D list somelist = [[1,2,3], [0, 3, 2], [1,9, 6]]; Then, take the nested for loop for traversing into the list, outer loop for traversing into the row and inner loop for traversing into the column Syntax: For intertor1 in range(start, stop, step): For intertor2 in range(start, stop, step): Statements Then, we have to check for the value if it is 1 then display the corresponding row and column Like this: #nested loop for traversing for i1 in range(len(somelist)): #traversing in column for i2 in range(len(somelist[i1])): #store the value value = somelist[i1][i2]; #check for the value 1 if(value == 1): #display the index value print 'the index of value is [%d][%d] ' % (i1,i2) PROGRAM: #initialize 2D list somelist = [[1,2,3], [0, 3, 2], [1,9, 6]]; #nested loop for traversing for i1 in range(len(somelist)): #traversing in column for i2 in range(len(somelist[i1])): #store the value value = somelist[i1][i2]; #check for the value 1 if(value == 1): #display the index value print 'the index of value is [%d][%d] ' % (i1,i2)

Subject: Java Programming

TutorMe
Question:

You have to create a program for ATM Which would have certain defined denominations of notes: 100,200, 500, and 2000 INR. Now you have to design your ATM in such a way that at any time ATM can be top-up with any required domination like I can add 41000 like (2000 x 20) + (500 x 2) notes Your ATM should have a function to withdraw cash, the input can be any amount: Use cases for withdrawing as below: 1: if the amount is not present show error insufficient balance 2: if the amount is not in the factor of available denominations show an error to ask for a multiple of the available denomination 3: first largest denomination should be used than smaller: like if I opt for 2300 rs, amount dispatched should be (2000 x 1 ) + (200 x 1) + (100 x 1) 3.b: if any denomination is not there like suppose you don’t have 2000 notes left in ATM , then, amount dispatched should be (500 x 4) + (200 x 1) + (100 x 1)

Inactive
Vikas N.
Answer:

import java.util.ArrayList; import java.util.Scanner; class Currency{ int value; } class note2000 extends Currency{ note2000(){ value = 2000; } } class note500 extends Currency{ note500(){ value = 500; } } class note200 extends Currency{ note200(){ value = 200; } } class note100 extends Currency{ note100(){ value = 100; } } public class ATM { private ArrayList<note2000> notes2000 = new ArrayList<note2000>(); private ArrayList<note500> notes500 = new ArrayList<note500>(); private ArrayList<note200> notes200 = new ArrayList<note200>(); private ArrayList<note100> notes100 = new ArrayList<note100>(); private void topUp(Currency notes[]) { for(int i=0;i<notes.length;i++) { if(notes[i] instanceof note2000) { notes2000.add((note2000) notes[i]); }else if(notes[i] instanceof note500) { notes500.add((note500) notes[i]); }else if(notes[i] instanceof note200) { notes200.add((note200) notes[i]); }else if(notes[i] instanceof note100) { notes100.add((note100) notes[i]); } } } private ArrayList<Integer> withDraw(int amount) { int count2000=0, count500=0, count200=0, count100=0; ArrayList<Integer> countNotes = new ArrayList<Integer>(); // count notes using Greedy approach if(notes2000.get(0) != null) { count2000 = amount/2000; amount -= count2000*2000; countNotes.add(count2000); } if(notes500.get(0) != null) { count500 = amount/500; amount -= count500*500; countNotes.add(count500); } if(notes200.get(0) != null) { count200 = amount/200; amount -= count200*200; countNotes.add(count200); } if(notes100.get(0) != null) { count100 = amount/100; amount -= count100*100; countNotes.add(count100); } return countNotes; } public static void main(String[] args) { Scanner scn = new Scanner(System.in); System.out.print("Enter the amount: $"); int amount = scn.nextInt(); if(amount<=100) { System.out.println("Insufficient balance"); return; } if(amount%100 != 0) { System.out.println("Not Multiple of available denomination"); return; } ATM atm = new ATM(); note2000 c2000 = new note2000(); note500 c500 = new note500(); note200 c200 = new note200(); note100 c100 = new note100(); Currency notes[] = {c2000, c500, c200, c100}; atm.topUp(notes); ArrayList<Integer> arr = atm.withDraw(amount); for(int i=0;i<arr.size();i++) { if(arr.get(i)!=0) { System.out.println(notes[i].value+" "+arr.get(i)); } } System.out.println(); } }

Subject: C++ Programming

TutorMe
Question:

A program that read the text file and stores the data in the parallel array, then calculate the sum of x, the sum of y, the sum of the product of x and y, calculate the average of x and y and then find the slope and intercept then display the line equation

Inactive
Vikas N.
Answer:

First, you have to declare the variable for storing the value and then take the input from the user for a filename Like this: //declaration string fileName; double temp, res; int i=0; //take the user input cout<<"Enter the file name: "; cin>>fileName; Then, declare the two arrays and then open the file and take the loop for traversing into the file and then read the data from the file and store in the array. It also checks if the file is open or not using the if-else statement Syntax: If(condition){ Statement }else{ Statement } Like this: /declare the array double temperature[20]; double resistance[20]; ifstream myfile; //open the file myfile.open(fileName); //check for file open or not if (myfile.is_open()) { //loop for read all the file data while (myfile.good()) { //store in the variable myfile >> temp >> res; //store in the parallel array temperature[i]=temp; resistance[i++]=res; } }else{ cout<<"File not open"<<endl; } Then, we have to reopen the file and then count the number of data in the file and then perform the calculation like the sum of x, the sum of y, the sum of the square of x, the sum of the product of x and y Like this: //initialize int count=0; double sumX=0, sumY=0, sumSquareX=0, sumXY=0; myfile.open(fileName); //check for file open or not if (myfile.is_open()) { //loop for read all the file data while (myfile.good()) { myfile >> temp >> res; //calculation sumX += temperature[count]; sumY += resistance[count]; sumSquareX += temperature[count]*temperature[count]; sumXY += temperature[count]*resistance[count]; count++; } }else{ cout<<"File not open"<<endl; } Then, calculate the average of x and y and then find the slope of the line using the given formula Then, calculate the y-intercept by subtracting from average of y, a product of slope and average of x and then display the output in a format Like this: //calculation double averageX = (sumX/count); double averageY = (sumY/count); double slope = (sumXY - sumX*averageY)/(sumSquareX-(sumX*averageX)); double b = averageY - slope*averageX; //display cout<<"Equation of least squares line: "<<"y = "<<fixed<<setprecision(3)<<slope<<"x + "<<b<<endl; PROGRAM: #include<iostream> #include<fstream> #include<iomanip> using namespace std; //main function int main(){ //declaration string fileName; double temp, res; int i=0; //take the user input cout<<"Enter the file name: "; cin>>fileName; //declare the array double temperature[20]; double resistance[20]; ifstream myfile; //open the file myfile.open(fileName); //check for file open or not if (myfile.is_open()) { //loop for read all the file data while (myfile.good()) { //store in the variable myfile >> temp >> res; //store in the parallel array temperature[i]=temp; resistance[i++]=res; } }else{ cout<<"File not open"<<endl; } myfile.close(); //initialize int count=0; double sumX=0, sumY=0, sumSquareX=0, sumXY=0; myfile.open(fileName); //check for file open or not if (myfile.is_open()) { //loop for read all the file data while (myfile.good()) { myfile >> temp >> res; //calculation sumX += temperature[count]; sumY += resistance[count]; sumSquareX += temperature[count]*temperature[count]; sumXY += temperature[count]*resistance[count]; count++; } }else{ cout<<"File not open"<<endl; } myfile.close(); //calculation double averageX = (sumX/count); double averageY = (sumY/count); double slope = (sumXY - sumX*averageY)/(sumSquareX-(sumX*averageX)); double b = averageY - slope*averageX; //display cout<<"Equation of least squares line: "<<"y = "<<fixed<<setprecision(3)<<slope<<"x + "<<b<<endl; }

Contact tutor

Send a message explaining your
needs and Vikas will reply soon.
Contact Vikas

Request lesson

Ready now? Request a lesson.
Start Lesson

FAQs

What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Lesson" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.