Question

In: Computer Science

How to compile this code on Visual Studio? Because it keeps getting me an error when...

How to compile this code on Visual Studio?

Because it keeps getting me an error when i compile it.

#include<iostream.h>
#include<cio.h>
class Array
{
public:

Array(int=0)//initalise the array with 0 value

Array(const Array &);
~Array();
private:
int size;
int *arr;
bool setvalue(int index,int value);
bool getvalue(int index,int &value);

Array & increment();
int getsize();
void print();
Array &Add(const Array arr);
bool Equal(const Array *arr)const;
Array &removeAt(int index);
Array &insertAt(int index,int value);

}; //End of Array class


void Array::setvalue(int index,int value) //set value for array
{
i=index;
x=value;
}
void Array::getvalue(int index,int value) //get array element
{
i=index;
x=&value;
}

void Array::getsize() //return the size of the array
{
cout<<arr.size();

}

void Array::print() //display array element
  
{
cout << x<endl;   
}
void Array::Add(int arr[])
{

int i;
for (i = 0; i < 5; i++)
arr[i]++; // this alters values in array in main()

}


void main()

{

Array A;
int arr[5];
  

cout << "Please Enter " << A.getSize() << " elements for A1 :";

int x;

for (int i = 0; i < A.getSize(); i++)

{

cin >> x;

A.setValue(i, x);

}

Array B(5);

cout << "Please Enter " << B.getSize() << " elements for B : ";

for (int i = 0; i < B.getSize(); i++)

{

cin >> x;

B.setValue(i, x);

}

cout << "Testing copy constrcutor : Array X(A); D = ";

Array X(A);

X.print();

cout << endl;

cout << "I am printing A using getValue assuming that I don't know the size,\nA = ";

int i = 0;

while (A.getValue(i, x))

{

cout << x << " ";

i++;

}

cout << "\nArray C = A.increment(), printing (using A.print()) A and C after the function call\nA = ";

Array C = A.increment();

A.print();

cout << "\nC = ";

C.print();

cout << "\nA.Equal(C) = " << A.Equal(&C) << endl;

cout << "A.Equal(B) = " << A.Equal(&B) << endl;

cout << "Array D = A.Add(B) = ";

Array D = A.Add(B);

D.print();

cout << "\nA is ";

A.print();

cout << "\nB is ";

B.print();

cout << endl;

cout << "Inserting 99 at index 99999 in A, the result is :\n";

A.insertAt(99999, 99);

A.print();

cout << endl;

cout << "Inserting -99 at index -99999 in A, the result is :\n";

A.insertAt(-99999, -99);

A.print();

cout << endl;

cout << "Inserting 7 at index 3 in A, the result is :\n";

A.insertAt(3, 7);

A.print();

cout << endl;

cout << "Deleting the element at index 2 from A, the result is :\n";

A.removeAt(2);

A.print();

cout << endl;
getch();
}

Solutions

Expert Solution

#include<iostream.h>

#include<conio.h>

class Array

  {

    public:

Array(int=0)              //initalise the array with 0 value

    Array(const Array &);

    ~Array();

    private:

    int size;

    int *arr;

    bool setvalue(int index,int value);

    bool getvalue(int index,int &value);

    Array & increment();

    int getsize();

    void print();

    Array &Add(const Array arr);

    bool Equal(const Array *arr)const;

    Array &removeAt(int index);

    Array &insertAt(int index,int value);

    }; //End of Array class

    void Array::setvalue(int index,int value)               //set value for array

      {

            i=index;

            x=value;

      }

    void Array::getvalue(int index,int value)                //get array element

      {

            i=index;

            x=&value;

      }

    void Array::getsize() //return the size of the array

      {

        cout<<arr.size();

      }

    void Array::print() //display array element

      {

         cout << x << endl;   

      }

    void Array::Add(int arr[])

      {

        int i;

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

           arr[i]++;                                       // this alters values in array in main()

      }

    void main()

    {

        Array A;

        int arr[5];

        cout << "Please Enter " << A.getSize() << " elements for A1 :";

        int x;

        for (int i = 0; i < A.getSize(); i++)

           {

            cin >> x;

            A.setValue(i, x);

           }

        Array B(5);

        cout << "Please Enter " << B.getSize() << " elements for B : ";

    

        for (int i = 0; i < B.getSize(); i++)

             {

                cin >> x;

                B.setValue(i, x);

             }

    

        cout << "Testing copy constrcutor : Array X(A);

        D = " ";

    

        Array X(A);

        X.print();

        cout << endl;

        cout << "I am printing A using getValue assuming that I don't know the size,\nA = ";

        int i = 0;

    

         while (A.getValue(i, x))

          {

            cout << x << " ";

            i++;

          }

        cout << "\nArray C = A.increment(), printing (using A.print()) A and C after the function call\nA = ";

        Array C = A.increment();

        A.print();

        cout << "\nC = ";

        C.print();

        cout << "\nA.Equal(C) = " << A.Equal(&C) << endl;

        cout << "A.Equal(B) = " << A.Equal(&B) << endl;

        cout << "Array D = A.Add(B) = ";

        Array D = A.Add(B);

        D.print();

        cout << "\nA is ";

        A.print();

        cout << "\nB is ";

        B.print();

        cout << endl;

    

        cout << "Inserting 99 at index 99999 in A, the result is :\n";

        A.insertAt(99999, 99);

        A.print();

        cout << endl;

        cout << "Inserting -99 at index -99999 in A, the result is :\n";

        A.insertAt(-99999, -99);

        A.print();

        cout << endl;

        cout << "Inserting 7 at index 3 in A, the result is :\n";

        A.insertAt(3, 7);

        A.print();

        cout << endl;

        cout << "Deleting the element at index 2 from A, the result is :\n";

        A.removeAt(2);

        A.print();

        cout << endl;

     getch();

    }

}    


Related Solutions

I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib>...
fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib> #include <ctime> void insertion_sort(int array[], int size, int start); void heap_sort(int B[], int n); void build_max_heap(int B[], int n); void max_heapify(int B[], int i, int n); void quick_sort(int B[], int p, int r); int partition(int B[], int p, int r); int main() {    int m = 10, Nf = 20000, Ns = 1000, delta = 1000, A[m][Nf];    for (int i = 0;...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method is not static in class StaticInitializationBlock, please define the main method as:    public static void main(String[] args) This is what I'm working on class A { static int i; static { System.out.println(1); i = 100; } } public class StaticInitializationBlock { static { System.out.println(2); } public static void main(String[] args) { System.out.println(3); System.out.println(A.i); } }
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write...
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write a simple assembly language program that performs a few arithmetic operations. This will require you to establish your programming environment and create the capability to assemble and execute the assembly programs that are part of this course. Your \student ID number is a 7-digit number. Begin by splitting your student ID into two different values. Assign the three most significant digits to a variable...
Complete the 3 programming problems in this assignment by using Microsoft Visual Studio Suite. Compile your...
Complete the 3 programming problems in this assignment by using Microsoft Visual Studio Suite. Compile your solutions for each problem solved in a Word or Google document which includes (a) the pseudocode, (b) the C# codes and (c) the execution result (screen capture just the answer part using Snipping Tool, avoiding non-related or blank spaces). Notice for readability, that the (a) & (b) are in text mode and the (c) is in image mode. Use proper titles and wording in...
Complete the 3 programming problems in this assignment by using Microsoft Visual Studio Suite. Compile your...
Complete the 3 programming problems in this assignment by using Microsoft Visual Studio Suite. Compile your solutions for each problem solved in a Word or Google document which includes (a) the pseudocode, (b) the C# codes and (c) the execution result (screen capture just the answer part using Snipping Tool, avoiding non-related or blank spaces). Notice for readability, that the (a) & (b) are in text mode and the (c) is in image mode. Use proper titles and wording in...
Complete this programming problem in this assignment by using Microsoft Visual Studio Suite. Compile your solutions...
Complete this programming problem in this assignment by using Microsoft Visual Studio Suite. Compile your solutions for each problem solved in a Word or Google document which includes (a) the pseudocode, (b) the C# codes and (c) the execution result (screen capture just the answer part using Snipping Tool, avoiding non-related or blank spaces). Notice for readability, that the (a) & (b) are in text mode and the (c) is in image mode. Use proper titles and wording in the...
Need it in C# using visual studio (also can you show me how to implement the...
Need it in C# using visual studio (also can you show me how to implement the code in vs) Create a New Project named Preferred Customer to be used in a retail store for preferred customers, where customers can earn discount on all purchases depending upon how much money they are going to spend. To begin with designing your Application, you must add a class named Person with properties for holding a Person’s Name, Address and Telephone Number. Next step...
I'm getting an error message with this code and I don't know how to fix it...
I'm getting an error message with this code and I don't know how to fix it The ones highlighted give me error message both having to deal Scanner input string being converted to an int. I tried changing the input variable to inputText because the user will input a number and not a character or any words. So what can I do to deal with this import java.util.Scanner; public class Project4 { /** * @param args the command line arguments...
I'm having a problem getting my code to function correct, *num_stu keeps losing its value when...
I'm having a problem getting my code to function correct, *num_stu keeps losing its value when ever another function is called from the class. Can someone proof read this for me and let me know what'd up? Header.h file #include <iostream> using namespace std; class report {    private:        int* num_stu;         int xx;        int* id;        double* gpa;    public:                report(int x) {             num_stu = &x;             xx = x;            ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT