C# :: Creating Complex Number Calculator - Convert String To Ints

Sep 18, 2012

I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.

Enter operand1: 3 4
operand1: (3, 4)
Enter operation : +
Enter operand2: 1 2
(3, 4) + (1, 2) = (4, 6)

My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.

View 4 Replies


ADVERTISEMENT

C :: Creating Struct Which Represents Complex Number

Feb 26, 2015

1 create a struct called complex which reprensts a complex number . both the real and imaginary compoents should be represented as doubles . ( 1 marks) .

2 write down a function called magnitude which has one parameter ( a struc complex) and a return type of double . it should return the maginude of the given parameter . ( 3marks) .

3 write a function called find_largest which has two parameter (one of type struct complex const * and the other type int) and a return type of struc complex . the two parameter represent an array of complex numbers and number of elements in that array . the function should return elements from array which has largest magnitude . this fucntion must called the magnitude function . ( 5 marks)

4 write a main function . your main fucntion . Your main fucntion should repeately prompt the user for complex number , storing them in an array. you should continuing reading in complex number until the user enters in both componets , at this point you should stop . you should not make an assumptions how many complex number the user will enter , ( i.e use realloc) after reading in complex numbers from the user you should print out real and imaginary components of the complex number with the largest magnitude.

Code:

#include<stdio.h>
struct complex {
double real;
double imag;

[code]....

View 5 Replies View Related

C/C++ :: Converting String Of Ints To A Vector Of Ints?

May 8, 2014

I am getting a string from the consle and that all works fine. I'm expecting a string of number, ie 123456.... I store that fine in my string object. I then need to take each individual number, ie 1, and put it in a vector then take the next number, ie 2, and put that in the next element in my vector.

Everything i've found and does eaither takes the entire string and stores it as an int, or takes the ascii representation of the number and stores that. How do I seperate each individual number and store them seperatly. below is a few different variations i've tried that doesn't produce my desired results.

cout<<"Please type the memory memory frames (numbers 0-9) to be used to simulate the input memory "<<endl;
cout<<"Your input: ";
string line="";
cin>>line;
cout<<"
Please wait while your input is processed and validated..."<<endl;

[code].....

the only thing i havn't tried yet is string streams and i don't necessarly like using them. Am i going to have to go that route? will that even work?

EDIT:I forgot to mention that this is being done on linux and then ported to unix.

View 7 Replies View Related

C++ :: Creating Exact Age Calculator?

Aug 3, 2014

I've been wondering this, since there is so many things which needs to be taken care of. I created one, but it wasn't precise.

View 19 Replies View Related

C/C++ :: Complex Number Guessing Game (SOS)

Mar 12, 2014

the only problem I have is where to add

want to play again? y
OK, I am thinking of a number. Try to guess it.
Your guess?
...

want to play again? no
Goodbye

Code :

#include <stdio.h>
#define TARGET 23
#define LOW 1
#define HIGH 100
#define TRUE 1
#define FALSE 0
#define GUESS 6
int process( int guess, int target );

[Code] ....

View 1 Replies View Related

C :: Convert Decimal Number To Binary And Store It In A String

Apr 16, 2014

I want to convert a decimal number to binary and store it in a string so that I can use that binary output for later computation. Here is what I did

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()

[Code] ....

​Now as you can see that all the binary output is in a[] but how do I get it into a string so that I can use something like printf("%s",string) and get the binary output ?

View 7 Replies View Related

C++ :: Operator Overloading In Complex Number Class

May 29, 2013

Write c/c++ code of overloading ^operator in complex number class.

If we have two objects of complex number class as fellows,complex obj3 =obj1 ^obj2 ;

Obj3 reak and imaginary pars will be ,

Obj3.real = (obj1.real)obj2.real
And
obj3.img = (obj1.img)obj2.img

View 1 Replies View Related

C++ :: Program That Takes Two Complex Number And Return Their Sum?

Oct 25, 2013

you have been tasked to write a program that takes two complex number and return their sum.However the + operator will not worl with complex numbers and you figure you need to verload the + and the assignment opeartor=.Ypu have come across the program [URL]

implement it and the client code to see it rune for the following complex numbers:

c1=3.0-4i,c2=8+4i

i have 3 files,driver.cpp,Complexnumber.cpp and complexNumber.h

complex.cpp is as follows

#include <iostream>
using namespace std;
class ComplexNumber {
private:
double real;
double image;

[code]....

View 4 Replies View Related

C++ :: Getting Multiple Ints From String Data

Feb 18, 2013

I'm having trouble making a .obj loader at present I'm trying to load faces that are defined as follows:

f 1/1/1 2/2/2/ 3/3/3

So far I've separated the the three number groupings into three strings, I've had a few issues with stringstreams and would like a simple solution.

View 1 Replies View Related

Visual C++ :: Using Imaginary Number - How To Declare Complex Numbers

Aug 13, 2013

I created an algorithm that uses imaginary numbers. It is fine on Dev C++, and now I am trying to port to VS2008. I figured out most things, including how to declare complex numbers. However, I've been having an incredible hard time trying to figure how to use the " i " number! For example:

In Dev C++:

Code:
z_cmplx = cexp(I * f1/Fs * 2 * PI);

Where "I" is a macro from the library!

In VS2008:

Code:
z_cmplx = std::exp(I * f1/Fs * 2 * PI);

Although I DID include <complex> library just like I did before, the compiler gives me: error C2065: 'I' : undeclared identifier.

View 10 Replies View Related

C :: Creating Simple Calculator By Splitting The Program In 3 Files

Feb 21, 2014

I am new to C programming, I have been given an assignment to create a simple calculator by splitting the program in 3 files. It should have 2 .c files and 1 .h... I went through the internet extensively and could only come up with this.

main.c:

Code:

//Calculator main.c
#include <stdio.h>
#include <conio.h>
#include "Functions.h"
int main() {
float x = 0, y = 0;
int operation;

[Code]...

Functions.c

Code:

#include "Functions.h"
extern float x, y;
float addition (float a, float b) {
return a + b;

[Code]...

Functions.h

Code:

#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
float Sum(float a, float b);
float difference (float a, float b);
float remainder (float a, float b);
float product (float a, float b);
#endif

When I do a 'cl main.c' on the Developer Command window for VS2013, i get an error that reads :

main.obj
main.obj : error LNK2019: unresolved external symbol _difference referenced in function _main
main.obj : error LNK2019: unresolved external symbol _product referenced in function _main
main.obj : error LNK2019: unresolved external symbol _addition referenced in function _main
main.exe : fatal error LNK1120: 3 unresolved externals

View 5 Replies View Related

C++ :: Creating Binary Calculator - Output Operation Of Subtraction

Feb 10, 2014

I need to create a binary calculator that outputs the operation of subtraction whenever you input 2 4 bit binary numbers. For example:

If I enter

1000
- 0111

View 1 Replies View Related

C/C++ :: Open A File And Use Overloaded Operators For Complex Number Class

Apr 10, 2015

This code is meant to open a file and use overloaded operators for a complex number class. I am getting a lot of errors in my class declaration/definition but I am not sure why.

#include <iostream>
#include <cmath>
#include <fstream>
class CN {
public:
double real;
double im;

[Code] ....

View 5 Replies View Related

C++ :: Calculator Using Stack - How To Convert Operation From Infix To Postfix

Sep 25, 2013

I trying to write a code for a calculator using stack is how to convert an operation from infix to postfix . Here is my attempt I created a header file.

#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;
template<class T>
struct node {
T item;

[Code] .....

View 1 Replies View Related

C++ :: Convert Base 10 To Base X Number Within String Of Characters

Apr 15, 2013

How would you convert say "238273615237287352536266362524382737272" base 10 to a base x number contained within a string of characters?

View 2 Replies View Related

C :: Calculator - Input Specific Number?

Feb 11, 2013

In my calculator, I am trying to make it so that you put enter 1 to add, 2 to subtract, 3 to multiply, and 4 to divide. I am facing the issue of making it so that you must enter a number, however instead of it being any number, it must be 1, 2, 3, or 4, and if it is not any of those numbers, you must re-enter the number. Here is a little snippet of my code:

Code:

printf("Please enter 1 to add, 2 to subtract, 3 to multiply, or 4 to multiply: ");
while (scanf("%d", &input) != 1) {
while (getchar() != '
');
printf("Invalid option. Please try again: ");

[Code] ....

how I can make the loop affect specific numbers.

View 4 Replies View Related

C/C++ :: Calculator With Differing Number Of Variables

Jan 31, 2015

I'm working on an assignment where the user inputs the center coordinates(x,y) for an circular array of (x,y) points. The program performs some calculations, then outputs the position of each point, based on the diameter and center location.

The issue I'm having is that the number of points is a variable(inputted by the user). How to make the program perform the calculations for a different number of points each time.

Code:

// Bolt position Calculator
// Calculates position of bolts on plate using number of points, hole diameter, and (x,y) coordinate of center

#include<iostream>;
#include<math.h>;
#include<cmath>;
#define PI 3.14159
using namespace std;
int main() {
int n,xn,yn
float D,x,y,A;

[Code] ......

View 2 Replies View Related

C++ :: Basic Calculator - User Will Have To Press Enter After Every Number

Mar 22, 2013

I'm stuck because I can make the calculator just find but the user will have to press enter after every number, what is s solution to this?

#include <iostream>
#include <string>
using namespace std;
int a = 1, b, c;
string symbol;
int multiplyFunction();

[Code] .....

View 6 Replies View Related

C++ :: BAC Calculator - String Stream Search

May 14, 2013

I am working on a project which is a fairly simply BAC calculator. I am attempting to grab data from a text file, which contains state abbreviation, maximum BAC before aggravated, and minimum license suspension. The text file looks like

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <stdio.h>
#include <ctype.h>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
#include <sstream>
using namespace std;

float MALE_RATE = 0.68, FEMALE_RATE = 0.55, LEGAL_LIMIT = 0.08;
//percent of body weight which holds alcohol

[Code] ....

The code I am struggling with is the getline and stringstream which is near the bottom.

The output I am getting is

The maximum BAC before aggrevated DUI in AL is .15
The minimum penalty in AL is 90 day suspension of license

I get that for every state I type. I know it is reading the first line, but something in my code does not allow it to read the other lines

View 1 Replies View Related

C++ :: Creating Program With Parameters To Convert Pounds To Euros

Jan 22, 2015

m creating a program with parameters to convert pounds to euros.

I keep getting this errorc2447: '{' missing function header for the line 'void showPriceInEuros' ....

#include <iostream> //for cin >> and cout <<
#include <cassert> //for assert
#include <iomanip> //for endl
#include <Windows.h>
using namespace std;
void processAPrice();
int getPriceInPounds();
int convertPriceIntoEuros(int pounds);

[Code] ....

View 1 Replies View Related

C++ :: Convert 8-digit Binary Number To Decimal Number?

Jul 6, 2013

Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.

Sample Output 1:

8-bit Binary Number => 11111111
Decimal Number = 255

Sample Output 2:

8-bit Binary Number => 10101010
Decimal Number = 170

Sample Output 3:

8-bit Binary Number => 101010102
Number entered is not a binary number

#include <iostream>
using namespace std;
int main()
{
int num;

[code]....

View 2 Replies View Related

C# :: Calculator With Buttons - When Click Numbers Or Operators It Goes To String Array

Mar 26, 2012

I have a calculator with buttons, and when I click the numbers or operators, it goes to a string array. So;

Press 3
Press +
Press 2
Press =

and my array is str[0]='3' str[1]=.... so on...

And also I have a C code which calculates the string you entered with some algorhytms and gives a double value as a result. So the question is;

How can I send my STR array in C# to my C program? I mean I want to use my C program as a source code. and How to return that double value to my C# program?

For now, I don't want to change my C codes into C# codes. I want it to keep as is. Just use it as a source code. Is that possible?

View 2 Replies View Related

C++ :: Convert Binary Number Into A Decimal Number

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "8-bit Binary Number=";
cin >> num;

[Code] .....

How can I get started with the body?

View 7 Replies View Related

C++ :: Convert Binary Number Into Decimal Number?

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

#include <iostream>
using namespace std;
int main()

[Code].....

May I know that how can I get started with the body?

View 5 Replies View Related

C# :: Unable To Implicit Convert Type Int To String Though Declared Variables As String

Mar 26, 2014

Ok, so I'm writing this code and when I build it keeps saying cannot implicitely convert type int to string even though I declared my variables as string. Why is it giving me this error?

private static string Repair()
{
string result="";
string beep;
string spin;
Console.WriteLine("Does your computer beep on startup?:(y,n)");

[Code]...

View 3 Replies View Related

C++ :: Convert And Return C Format String To String?

Jun 8, 2014

heres the function:

string ToString ( const char * format, ... )
{
char buffer[256];

[Code]....

these function do the same of the sprintf() function. but instead we use a variable for add the result, i want to return the result. when i use it:

string f;
f=ToString("hello world");
gives me several errors:
"error: crosses initialization of 'std::string f'"
"error: jump to case label [-fpermissive]"

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved