Question

In: Computer Science

using System; using System.Data.SqlTypes; using System.Globalization; using System.Reflection.Metadata.Ecma335; using System.Runtime.Intrinsics.X86; using System.Security.Cryptography.X509Certificates; namespace ConsoleApp4 { class...

using System;
using System.Data.SqlTypes;
using System.Globalization;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.Intrinsics.X86;
using System.Security.Cryptography.X509Certificates;

namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
AO function = new AO(1000, 3);
function.Find();
}
}
class AO
{
public a(long _max , long _least)
{
max = _max;
least = _least;
numm = new long[1000];
}
public long max;
public long least;
public long[] numm;
public long Find()
{
long per =0;
long sum = 0;
for(int i=1; i<=max; i++)
{
  
for(int j=0;j<i;j++)
{
if(j%i==0)
{   
sum = sum + j;
per++;
}
if (sum != i)
continue;
else
numm[per] = i;

}
}
return per;
}
  
}
  

}

Please let me know why it doesn't work.

Solutions

Expert Solution

Below is the correct program.

Constructor should have the same name ast that of class.

Replaced below statment

public a(long _max , long _least)

with

public AO(long _max, long _least).

Also no need to include unnecessary packages in your program.

using System.Data.SqlTypes;
using System.Globalization;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.Intrinsics.X86;
using System.Security.Cryptography.X509Certificates;

Below is the correct program, which is compiling fine and working

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            AO function = new AO(1000, 3);
            function.Find();
        }
    }
    class AO
    {
        public AO(long _max, long _least)
        {
            max = _max;
            least = _least;
            numm = new long[1000];
        }
        public long max;
        public long least;
        public long[] numm;
        public long Find()
        {
            long per = 0;
            long sum = 0;
            for (int i = 1; i <= max; i++)
            {

                for (int j = 0; j < i; j++)
                {
                    if (j % i == 0)
                    {
                        sum = sum + j;
                        per++;
                    }
                    if (sum != i)
                        continue;
                    else
                        numm[per] = i;

                }
            }
            return per;
        }

    }


}

Related Solutions

Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace...
Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace ConsoleApp_Patient { class Patient //C# class { //private fields for patientid, lastname,firstname, age, and email. private int patientid; private string lastname; private string firstname; private int age; private string email; //public data items for each of these private fields with get and //set methods public int PatientID //Public field for patientid { get { return patientid; } set { patientid = value;//set patinetid }...
Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace...
Patient.cs : //namespace using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //application namespace namespace ConsoleApp_Patient { class Patient //C# class { //private fields for patientid, lastname,firstname, age, and email. private int patientid; private string lastname; private string firstname; private int age; private string email; //public data items for each of these private fields with get and //set methods public int PatientID //Public field for patientid { get { return patientid; } set { patientid = value;//set patinetid }...
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Assignment07 { class Dog { public void...
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Assignment07 { class Dog { public void bark(string dogsName) { int barking =5; while(barking < 5)    Console.WriteLine(dogsName + " is barking"); } public void run(string dogsName) { int running = 10; while(running > 10) Console.WriteLine(dogsName + " is running"); } } class Program { static void Main(string[] args) { Dog fido = new Dog(); fido.bark("Fido"); fido.run("Fido"); Console.Write("Hit any key to close"); Console.ReadKey(true); } } } need to create 2 while...
C++ please #include <iostream> using namespace std; /** * defining class circle */ class Circle {...
C++ please #include <iostream> using namespace std; /** * defining class circle */ class Circle { //defining public variables public: double pi; double radius; public: //default constructor to initialise variables Circle(){ pi = 3.14159; radius = 0; } Circle(double r){ pi = 3.14159; radius = r; } // defining getter and setters void setRadius(double r){ radius = r; } double getRadius(){ return radius; } // method to get Area double getArea(){ return pi*radius*radius; } }; //main method int main() {...
Given code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public...
Given code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class Car { // fields private decimal _CurrentSpeedMPH; // the cars current speed private decimal _MaxSpeedMPH; // the upper limit, the car cannot exceed this value private bool _EngineRunning; // true means the engine has been started and is running, false says engine is off public Car(decimal maxSpeed) // constuctor, user chooses to set maxSpeed as they create the object { _MaxSpeedMPH = maxSpeed;...
Given the partially coded project: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace...
Given the partially coded project: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StaticHW {    class Program { static void Main(string[] args) { // will have 3 Dogs Dog[] allDogs = new Dog[3]; allDogs[0] = new Dog(20f, 10f, "Fido"); allDogs[1] = new Dog(40f, 20f, "Percy"); allDogs[2] = new Dog(70f, 30f, "Snoopy"); // comment out the next 3 lines until you have written the Dog class and the code runs ok // then put these 3 lines...
Create a class library (.dll) in a particular namespace (using csc or VS2017) to define one...
Create a class library (.dll) in a particular namespace (using csc or VS2017) to define one or more classes, each contains fields, methods, constructors, and/or properties, including r/w properties, auto-implemented and/or expression-bodied properties.
I have a error code, for my C++ class, using Putty include <iostream> using namespace std;...
I have a error code, for my C++ class, using Putty include <iostream> using namespace std; int main() { char answer; char grade; cout << "Are you taking a class (enter y, Y, N or N): " << endl; cin >> answer; if (answer == 'N' || 'n'); { cout << "Thanks for using the system" << endl; } else if (answer == 'Y' || 'y'); { cout << "Enter a letter grade (A, B, C, D, or F): "...
Previous Lab Code files: PersonType.h: #include <string> using namespace std; class personType { public: void print()...
Previous Lab Code files: PersonType.h: #include <string> using namespace std; class personType { public: void print() const; void setName(string first, string middle, string last);    void setLastName(string last);    void setFirstName(string first);    void setMiddleName(string middle);    bool isLastName(string last) const;    bool isFirstName(string first) const; string getFirstName() const;    string getMiddleName() const;    string getLastName() const; personType(string first = "", string middle = "", string last = ""); private: string firstName; string middleName; string lastName; }; PersonTypeImp: #include <iostream>...
I want to indent this c++ program #include<iostream> using namespace std; class Rectangle{ private: double width;...
I want to indent this c++ program #include<iostream> using namespace std; class Rectangle{ private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; double getPerimeter() const; bool isSquare() const; }; void Rectangle::setWidth(double w){ width = w; } void Rectangle::setLength(double l){ length = l; } double Rectangle::getWidth() const{ return width; } double Rectangle::getLength() const{ return length; } // Added Method definitions double Rectangle::getArea() const{ return (width * length); } double Rectangle::getPerimeter() const{...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT