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.
Create a class to store a value that represents number of hours worked and number of days worked. Must ensure that the two representations are always consistent. I have to create 2 files, I'm pretty sure: a .cpp and a .h
This is what I have so far for my .h file (I know it's NOT functional...yet):
#include <iostream> using namespace std; class NumDays { private: double hours; double days;
[Code] ...
I don't know how to start / create this .cpp file to define the variables.
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.
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;
Im having trouble creating a struct within a struct node. the program suppose to hold students firstname, lastname, and gpa in a node therefore creating my linked list. Line 26 keeps saying that cannot convert parameter 2 from 'studentType to std::string
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.
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.
My address book will be simple, and the thing's that I'm expecting to use in it are :
Pointers, Linked Lists Malloc Structs Typedefs Makefile, header file Putting functions into different program files
I have started the program trying to create a struct, and getting it working with a couple of entries before going onto user input and splitting it up.
Code:
#include <stdio.h> #include <stdlib.h> int main(void) { // Struct type address book. Just a name, a number and a pointer
[Code] .....
I'm a bit lost at this point... My knee jerk thought is to create a for loop, and cycle through the list.
I'm not sure how this would apply to this though? Without using the familiar type of print loop such as :
Code: for (i = 0; ;i++) { printf("%i ", array[i]; }
I'm thinking that I need to create a temporary struct that can be used to assign the value of the next struct in the list, and then somehow print from that....
I'll try and write the logic out :
while temp != NULL (The last node value is assigned NULL to show us where the end of the list is)
create a temporary pointer that can be used to keep track of where we are in the list.
print out the current entry name and number
then assign the temp pointer value to the * next of the current struct. So if we are in entry1 the *next should be the address of entry 2.
Print out entry 2 name and number, assign entry 2 next to the temp value.
Design, implement, and test a class that represents an amount of time in minutes and seconds. The class should provide a constructor that sets the time to a specified number of minutes and seconds. The default constructor should create an object for a time of zero minutes and zero seconds. The class should provide observers that return the minutes and the seconds separately, and an observer that returns the total time in seconds (minutes x 60 + seconds). Boolean comparison observers should be provided that test whether two times are equal, one time is greater than the other, or one time is less than the other. (You may use RelationType and function ComparedTo if you choose). A function should be provided that adds one time to another, and another function that subtracts one time from another. The class should not allow negative times (subtraction of more time than is currently stored should result in a time of 0:00). This class should be immutable.
this is one of my main errors: Error1error C2653: 'Time' : is not a class or namespace namec:userskdesktop oane statecisp 1610visual studioschapter 12 assignmentchapter 12 assignmentchapter 12 assignment.cpp131Chapter 12 Assignment
I can’t figure out the syntax on how to generate random numbers for two members of a struct. It seems so simple because I know what I want to do, I just can’t make it work. I have the random generators I want but I don’t know how to pull it over into my struct.
Code: #include <stdio.h> #include <stdlib.h> #include <math.h> struct student { int id; int score;
How would I go about creating a random number generator (or pseduorandom I suppose) with user inputted lower and upper bounds along with a user inputted size of the sequence (so they can select how many random numbers they'd like outputted)?
I am creating a random number generator and have run into a problem with my do while loop. it continually prints one of the lines of output infinitely. what am i missing here?
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { unsigned seed = time(0);
I'm trying to create a program that creates random numbers. I looked through some examples and this is what I came up with. The time identifier seems to be undefined yet I see no reason it is undefined.
Code: #include "stdafx.h" #include <iostream> using namespace std; int main() { //Re-seed the random-number generator time_t now;
[code]...
here's my error code..
1>------ Build started: Project: bake, Configuration: Debug Win32 ------ 1> bake.cpp 1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(8): error C3861: 'time': identifier not found 1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(9): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Create a script that lets you rotate an image through some number of degrees(out of a maximum of 360 degrees). The script should let you specify that you want to spin the image continuously. It should let you adjust the spin speed dynamically.
I am trying to create a recursive function that i can call on in order to take a user inputed base and exponent and give final answer this is what i have but im completely lost after this i dont even know how to continue. What i have so far
#include <iostream> using namespace std; int Exp(int x,int y){ if(base <= 1 || exp == 0) return 1; if(exp == 1) return base; int main(){ int number, exp;
[Code] .....
After i set the base situations im not sure how to get the function to make the function take the base to the exponent recursively.
The output I'm getting here just counts every letter in the sentence and counts them as vowels. I'm trying to make the user defined function return the amount of vowels within the sentence.
I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...
i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....
------------- My Subroutine ---------------------------------------------------------------------- void charbytetostring(char input, char *output){ int i, remainder; char BASE=0x2; int DIGITS=8; char digitsArray[3] = "01";
[Code] ....
When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.
The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.
I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.
When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..
input = input / BASE; I get C9 where I expected to get 48.
My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?
I'm trying to create a program that allows the user to enter an unknown number of income and expense amounts. The program has to us see a while loop and display the income total, expense total, and total profit or loss. I've got it really close, but I'm doing the loop wrong. It counts the sentinel value (-1) towards the total, instead of just ending like it is supposed to.
#include <iostream> using namespace std; int main() { //declare variables double incomeInput; double expenseInput; double incomeTotal=0; double expenseTotal=0;
Each node (if its a 'normal' node) can have 2, 3 or 4 children. I know how to linearize a normal quadtree though it is not memory efficient in this case as the linearization only works for full trees. I'm okay with holes though.
But my tree is slightly odd in that it has non-normal nodes. For example, two leaves will point to a 'dead' node and that dead node has 3 children. Sometimes, 3 leaves will point to a dead node and that dead node will have 2 children. Sometimes, 4 leaves will point to a dead node and that dead node will have 4 children.
So normally, a node will only have one parent and multiple children or it'll just be a leaf. But there are dead nodes that can have 2, 3, or 4 parents and will subsequently have 3, 2 or 4 children respectively.
This is for point location within a Delaunay triangulation and operates off of the idea of volume spanning.
What I abstracted in my code is a 2-to-3, 3-to-2 and 4-to-4 flip. The idea is ,we take 2 tetrahedra and replace them with 3 good tetrahedra but they span the same volume which is good for point location.
As of now, the code that I have works fine. It triangulates tetrahedra and repairs them accordingly but for certain inserts, the search algorithm takes incredibly long and I'm trying to fix that.
I figured a linear structure would be a good attempt so how to linearize a tree that behaves almost polymorphically.
I have some complex declarations to simplify with typedef I have done a try
1. Code: char (*x[10]) (int); /* typedef char FUNC(int); typedef FUNC *FUNC_PTR; FUNC_PTR x[10]; */ Why we don't use * symbol in the last statement in front of FUNC_PTR?
I'm not sure if I was some weird syntax problem or the way Ive ordered things. But a conditional statement I have created is not performing the way I want it to.
When debugging, the condition was activated with the values:
xDif = -1 yDif = 1 prevXDif = -1 prevYDif = 0
However, I want the condition not to follow through as I am using the 'NOT' or '!' operator to negative the entire statement. For some reason, the line of code within the else if is still running.