Can someone help me with these question? Hope to get answer as soon as possible
ID: 3580087 • Letter: C
Question
Can someone help me with these question? Hope to get answer as soon as possible so I can study it.
12. A polynomial with one variable can be represented using an array of doubles. For example 3x2 2x + 1 can be represented by array {3, 2, 1}, and 4x3 + 2x + 3 can be represented by array {4, 0, 2, 3} and 5x4 +2x can be represented by array {5, 0, 0, 2, 0}. Write a method that takes an array of doubles named poly (representing a polynomial) and a double named number and returns the value of the polynomial at number.
15. Assume that there is a file named scores in the following format: Each row of the file has first name, last name followed by the score. Assume that bot first name and last names are single words, and score is an integer. For example, the contents file look like Don Knuth 99 Alan Turing 100 Edsger Dijkstra 98 Write a complete program that reads the contents of the file and outputs the average score.
17. Write a class named Triangle with following methods and constructors: A default constructor that sets all sides to be of length 1, a specific constructor that takes three parameters (representing the length of sides of the triangle), a method named perimeter that returns the perimeter of the Triangle, a method named type that returns a String describing whether the the triangle is isosceles (two equal sides), equilateral(three equal sides) or scalene (all sides are different).
Explanation / Answer
15)
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
ifstream f("input.txt");
string fname,lname;
int score;
int sum=0;
float avgscore;
int count=0;
while(f>>fname>>lname>>score)
{
cout<<fname<<" "<<lname<<" "<<score<<endl;
sum+=score;
count++;
}
avgscore=(float)sum/count;
cout<<"Average score is "<<avgscore<<endl;
}
==================================================================
input.txt
Don Knuth 99
Alan Turing 100
Edsger Dijkstra 98
===================================================
output:
akshay@akshay-Inspiron-3537:~/Chegg$ g++ qus.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Don Knuth 99
Alan Turing 100
Edsger Dijkstra 98
Average score is 99
============================================================
17)
#include<bits/stdc++.h>
using namespace std;
class Triangle
{
int s1,s2,s3;
public:
Triangle()
{
s1=1;
s2=1;
s3=1;
}
Triangle(int a,int b,int c)
{
s1=a;
s2=b;
s3=c;
}
int perimeter()
{
return s1+s2+s3;
}
void Type()
{
if(s1==s2&&s2==s3&&s1==s3)
{
cout<<"Equilateral Triangle ";
}else if(s1==s2||s2==s3||s1==s3)
{
cout<<"Isosceles Triangle ";
}
else
{
cout<<"Scalene Triangle ";
}
}
};
int main(int argc, char const *argv[])
{
Triangle t1;
Triangle t2(2,2,3);
cout<<"T1 is ";
t1.Type();
cout<<"T2 is ";
t2.Type();
cout<<"Perimeter of T1 is "<<t1.perimeter()<<endl;
cout<<"Perimeter of T2 is "<<t2.perimeter()<<endl;
}
======================================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ g++ qus.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
T1 is Equilateral Triangle
T2 is Isosceles Triangle
Perimeter of T1 is 3
Perimeter of T2 is 7
==================================================================
12)Please elaborate what do you mean by value of polynomial at number.Explain the question fully
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.