C++
Write the following 7 routines as member functions in two separate classes
-one involving a dynamic array and other a singularly linked list.
-Also write inside the classes other appropriate functions like constructor/s, copy constructor, overloaded assignment operator, destructor, and other operator overloaded functions as needed.
1.To generate 100 random numbers between 1-100 in a randomData.txt file
2.To read the 100 random numbers from randomData.txt and store them in a data structure,
3.print the data in the data structure
4.Find the smallest and the largest of the random numbers and position in the data structure
5.Insert 1000 in the 51th element of the data set
6.delete the first and last element of the data set.
7.sort the residual data set in an ascending order and print them.
I am including the code for a class which takes a dynamic array and does everything in the question.
#include<bits/stdc++.h>
#include<fstream>
#include<vector>
using namespace std;
fstream file;
class abcd
{
std::vector<int> v;
public:
abcd()
{
;
}
void generate()
{
srand(time(0));
for(int i=0;i<100;i++)
{
int
x=rand()%100+1;
file<<x<<" ";
v.push_back(x);
}
}
void Read()
{
char ch[5];
file>>ch;
cout<<ch<<"\n";
while(file>>ch)
{
cout<<ch<<"\n";
int x=0;
for(int
i=0;ch[i]!='\0';i++)
{
x=x*10+(ch[i]-'0');
}
v.push_back(x);
}
cout<<"\n";
}
void print()
{
for(int
i=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<"\n";
}
void snl()
{
// cout<<"herter";
int x=v[0],y=v[0],p=0,q=0;
for(int i=1;i<100;i++)
{
int s=x;
x=min(x,v[i]);
if(s!=x)
p=i;
s=y;
y=max(y,v[i]);
if(s!=y)
q=i;
}
cout<<x<<" @
"<<p<<"\n";
cout<<y<<" @
"<<q<<"\n";
}
void Insert()
{
v.insert(v.begin()+50,1000);
}
void Delete()
{
auto i=v.begin();
v.erase(i);
auto j=v.end()-1;
v.erase(j);
}
void printA()
{
sort(v.begin(),v.end());
print();
}
~abcd()
{
;
}
};
int main()
{
file.open("randomData.txt", ios::out | ios::in);
abcd A;
int n;
char ch='y';
while(ch=='y')
{
cin>>n;
if(n==1)
A.generate();
else if(n==2)
A.Read();
else if(n==3)
A.print();
else if(n==4)
A.snl();
else if(n==5)
A.Insert();
else if(n==6)
A.Delete();
else
A.printA();
cin>>ch;
}
return 0;
}
C++ Write the following 7 routines as member functions in two separate classes -one involving a...
12. Consider C++ class. Which one of the following choices is NOT correct? A. Class instances can be static, stack dynamic, or heap dynamic. B. If static or stack dynamic, they are referenced directly with value variables. C. If stack dynamic, they are referenced through pointers. D. Stack dynamic instances of classes are always created by the elaboration of an object declaration. E. The lifetime of such a class instance ends when the end of the scope of its declaration...
I need this in C++. This is all
one question
Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...
Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....
c++ only Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we’ll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct Node { int number; Node * nextNode;...
please write the code in
C++
2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...
8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code Your answers to this homework must be your own work.You are not allowed to share your solutions.You may not engage in any other activities that will dishonestly improve your results or dishonestly improve or damage the results of others. Plagiarism Plagiarism is when you copy words, ideas, or any other materials from another source without giving credit. Plagiarism is unacceptable in any academic environment....
Need helps on C++ attach. Thanks
Pointers with classes a) A user-defined class named Timer has a constructor that takes two integer parameters to initialize hour and minute data members. Write a single C++ statement to create an object of the Timer class using dynamic memory allocation and assign it to a pointer variable named timePt r. It should call the constructor with two parameters. Use values of 10 and 20 for hour and minute respectively. b) Write the definition...
solve it in c++10 Create a composition between the classes Job and Salary. Class Salary a. data member: 1. money b. constructors: 1. default constructor 2. user defined constructor with a parameter to set money c. standard accessor and mutator functions Class Job a. data members: title (name of the job) salary (object of type Salary) b. constructors: 1. default constructor 2. user defined constructor to set title and salary 3. implement constructor delegation c. standard accessor and mutator function...
IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...
please write in c++.
4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...