- Notifications
You must be signed in to change notification settings - Fork360
Square Sum Array Using C#249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletionsComplex_No_Addition.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include<iostream> | ||
| #include<math.h> | ||
| using namespace std; | ||
| class complex | ||
| { | ||
| public: | ||
| int real; | ||
| int img; | ||
| public: | ||
| complex() | ||
| { | ||
| int real=3; | ||
| int img=4; | ||
| cout<<"\nAdd:"<<real<<"+"<<img<<"i"; | ||
| } | ||
| complex(int a, int b) | ||
| { | ||
| real = a; | ||
| img = b; | ||
| } | ||
| }; | ||
| int main() | ||
| { | ||
| int real,img; | ||
| complex c; | ||
| complex c1(4,5); | ||
| complex c2(2,3); | ||
| real=c1.real+c2.real; | ||
| img=c1.img+c2.img; | ||
| cout<<"\nadd:"<<real<<"+"<<img<<"i"; | ||
| return 0; | ||
| } |
55 changes: 55 additions & 0 deletionsCount_Number_of_object.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //count the number of the objects in this program | ||
| #include<iostream> | ||
| using namespace std; | ||
| class myclass | ||
| { | ||
| private: | ||
| int a=8,b=9; | ||
| public: | ||
| myclass() | ||
| { | ||
| a=8; | ||
| b=9; | ||
| count++; | ||
| } | ||
| myclass(int x,int y) | ||
| { | ||
| a=x; | ||
| b=y; | ||
| count++; | ||
| } | ||
| static int count; | ||
| void display() | ||
| { | ||
| cout<<"\na= "<<a<<"\nb= "<<b<<endl; | ||
| } | ||
| static void count1() | ||
| { | ||
| cout<<"No of objects= "<<count<<endl; | ||
| } | ||
| }; | ||
| int myclass::count=0; | ||
| int main() | ||
| { | ||
| cout<<"\nFor object1--->"; | ||
| myclass s1; //creating object s1 with default constructor | ||
| s1.display(); //a=8 b=9 | ||
| s1.count1(); //count=0;---> count++;---> count=1 | ||
| cout<<"\nFor object2--->"; | ||
| myclass s2(20,60); //creating object s2 with parameterized constructor | ||
| s2.display(); // a=20 b=60 | ||
| s2.count1(); //count=1--->count++ ---> count=2 | ||
| cout<<"\nFor object3--->"; | ||
| myclass s3; //creating object s3 with default constructor | ||
| s3.display(); //a=8 b=9 | ||
| s3.count1(); //count=2--->count++ ---> count=3 | ||
| return 0; | ||
| } | ||
122 changes: 122 additions & 0 deletionsObject_Function_Argument.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| #include<iostream> | ||
| using namespace std; | ||
| class myclass | ||
| { | ||
| private: //Access specifier | ||
| int num; // num is private here | ||
| public: | ||
| //public section | ||
| void get_data() | ||
| { | ||
| cout<<"\nEnter a number: "; | ||
| cin>>num; | ||
| } | ||
| //set_data 3 times definition with different parameter-->method overloading list | ||
| void set_data(myclass passob) //copy means value | ||
| { | ||
| num=passob.num; | ||
| /* | ||
| calling object.num=passob.num | ||
| ob1.num=ob2.num | ||
| As passob(formal parameter) = ob2 (actual parameter) | ||
| for calling object we don't need to write the object | ||
| name to access properly within the method. | ||
| */ | ||
| } | ||
| void set_data(int a, myclass &passob) //call by reference | ||
| { | ||
| num=passob.num; | ||
| /* | ||
| calling object.num=passob.num | ||
| ob4.num=ob2.num | ||
| As passob(formal parameter) = ob2 (actual parameter) | ||
| for calling object we don't need to write the object | ||
| name to access properly within the method. | ||
| */ | ||
| } | ||
| void set_data(myclass *passob) //call by address | ||
| { | ||
| num=passob->num; | ||
| /* | ||
| calling object.num=passob->num | ||
| ob3.num=ob2.num | ||
| As passob(formal parameter) = ob2 (actual parameter) | ||
| for calling object we don't need to write the object | ||
| name to access properly within the method. | ||
| */ | ||
| } | ||
| void show_data() | ||
| { | ||
| cout<<"\nNum= "<<num; | ||
| } | ||
| }; | ||
| int main() | ||
| { | ||
| //we are declaring 4 objects of the class myclass | ||
| myclass ob1,ob2,ob3,ob4; | ||
| int a=0; | ||
| ob2.get_data(); | ||
| //ob2.num=user_value | ||
| ob1.set_data(ob2); //copy means value | ||
| /* | ||
| we are trying to set the value of ob1.num by | ||
| the value of ob2.num. | ||
| calling object= ob1 | ||
| passing object= ob2 | ||
| here we are passing an object ob2 within an object method ob1.set_data(..) | ||
| what is the data type of ob2? | ||
| it's defiend as myclass ob2; | ||
| so, data type of ob2 is user defined data | ||
| type that is my class. | ||
| Function calling line | ||
| function_name(actual_parameter); | ||
| Funtion definition line | ||
| return_type funtion_name(data_type formal_parameter); | ||
| { | ||
| .... | ||
| } | ||
| Target of ob1.set_data(ob2); | ||
| Target is to setup ob1.num=ob2.num | ||
| ------------------------------------------------- | ||
| for object ob1---> | ||
| ob1.num | ||
| ob1.get_data | ||
| ob1.set_data | ||
| ob1.set_data | ||
| ob1.set_data | ||
| ob1.show_data | ||
| --------------------------------------------------- | ||
| */ | ||
| ob3.set_data(&ob2); //address-->we are passing address of ob2 | ||
| ob4.set_data(a,ob2); //reference | ||
| ob1.show_data(); | ||
| ob2.show_data(); | ||
| ob3.show_data(); | ||
| ob4.show_data(); | ||
| return 0; | ||
| } | ||
| /* | ||
| int a | ||
| int is system defined data type | ||
| myclass myobj; | ||
| myclass is a user defined data type | ||
| myobj is an object here | ||
| */ |
28 changes: 28 additions & 0 deletionsSquare_Sum_Array.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* Take input the elements of an array. find the sum of their squares. */ | ||
| #include<stdio.h> | ||
| int main() | ||
| { | ||
| int arr[5],sum=0,val; | ||
| // Take inputs of an array | ||
| printf("Enter Elements: "); | ||
| for(int i=0;i<5;i++) | ||
| scanf("%d",&arr[i]); | ||
| // Calculation | ||
| for(int i=0;i<5;i++) | ||
| { | ||
| sum=sum+(arr[i]*arr[i]); | ||
| } | ||
| //Printing Result | ||
| printf("Values\t\tSquare Values"); | ||
| printf("\n"); | ||
| for(int i=0;i<5;i++) | ||
| { | ||
| printf("%d\t\t" "%d",arr[i],arr[i]*arr[i]); | ||
| printf("\n"); | ||
| } | ||
| printf("The Sum is: %d",sum); | ||
| return 0; | ||
| } |
77 changes: 77 additions & 0 deletionsTriangle.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /*Write a program in c++ that has a class Triangle and data members side1,side2 and side3. | ||
| //One method calarea() | ||
| Use default constructor | ||
| Parametrized constructor and copy constructor | ||
| */ | ||
| #include<iostream> | ||
| #include<math.h> | ||
| using namespace std; | ||
| class Triangle | ||
| { | ||
| private: | ||
| float side1,side2,side3; | ||
| float area; | ||
| public: | ||
| Triangle() | ||
| { | ||
| side1=6; | ||
| side2=6; | ||
| side3=6; | ||
| } | ||
| Triangle(float a,float b,float c) | ||
| { | ||
| area=0; | ||
| side1=a; | ||
| side2=b; | ||
| side3=c; | ||
| } | ||
| Triangle(Triangle &s) | ||
| { | ||
| side1=s.side1; | ||
| side2=s.side2; | ||
| side3=s.side3; | ||
| } | ||
| void calarea() | ||
| { | ||
| float s; | ||
| if(((side1+side2)>side3)||((side1+side3)>side2)) | ||
| { | ||
| s=(float)(side1+side2+side3)/2; | ||
| area=(float)sqrt(s*(s-side1)*(s-side2)*(s-side3)); | ||
| } | ||
| else | ||
| { | ||
| cout<<"\nTriangle is not valid"; | ||
| } | ||
| //cout<<area; | ||
| } | ||
| void display() | ||
| { | ||
| cout<<"\narea of the triangle:"<<area; | ||
| } | ||
| }; | ||
| int main() | ||
| { | ||
| Triangle s1; | ||
| s1.calarea(); | ||
| s1.display(); | ||
| Triangle s2(20,25,30); | ||
| s2.calarea(); | ||
| s2.display(); | ||
| Triangle s3(s2); | ||
| s3.calarea(); | ||
| s3.display(); | ||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.