i have only recently got into programming. i have this homework assignment that is frying my brains, the program needs to take a number from the user and give the 'reduced' sum. for example: if the user enters 888 then the sum should be: 6. it takes the number and adds its digits im just looking for a direction to where my problem is
#include "iostream.h" int reduction (int number) { return number/10+number%10; } int main() { int number,loopcount; cout<< "please enter a number"<<endl; cin>>number;
Assignment to make a rational numbers class as follows:
create a constructor that prevents a 0 denominator in a fraction, reduces or simplifies fractions that are not in reduced form, and avoids negative denominators.
Overload the addition, subtraction, multiplication and division operators for this class.
Overload the relational and equality operators for this class. My code so far is as follows:
Build started: Project: 11.10rationalnumberclass, Configuration: Debug Win32 ------ 1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Rational::setFraction(int,int)" (?setFraction@Rational@@QAEXHH@Z) referenced in function _main 1>C:UsersJacobDocumentsVisual Studio 2010ProjectsComplexnumbers11.8projectDebug11.10rationalnumberclass.exe : fatal error LNK1120: 1 unresolved externals
part of the problem might be that I cannibalized another program dealing with complex numbers to make this. While I don't need this class to be perfect, I'm not sure I entirely understand everything about classes and overloading yet.
RAT(RAT_INT num = 0, RAT_INT den = 1){ Num = num; Den = den;
[Code].....
Two questions: 1) In the second line in main, how does C++ know to convert 2 to the appropriate RAT? 2) Is it possible to make the third line in main valid without adding global operators for all the member operators to support plain integers?
My assignment is to handle rational numbers of different denominators...
Develop rational number class that can •add •subtract •multiply •divide •reduce to simplest form Your class must be able to handle rational numbers of different denominators
This is the errors I am getting
error C4716: 'Rational::addition' : must return a value error C4716: 'Rational::multiplication' : must return a value error C4716: 'Rational::division' : must return a value error C4716: 'Rational::subtraction' : must return a value
I'm having trouble finishing this program. What I'm trying to do is create a class for Rational numbers. Get input from user for denominator and numerator. Store the numbers without a sign, and for the sign store it separately in char. I'm not supposed to use accessor functions. The part that I can't seem to know how to do is use the info that was stored in the addUp function. This function need to add two rational numbers. i need to make this function general enough that it can handle two fractions, or a fraction and a whole number, or two whole numbers. What I already have here is readin function which reads in the numerator and denominator. setnumerator and setdenominator to assign positive values. setsign should get the sign of the fraction. Finally addUp should addUp which I explained before. I have some ideas about writing the tests, but can't seem to know how to implement it to the program. The main program is still empty but all I'm supposed to do there is call the class functions.
Code: #include <iostream> using namespace std; class Rational { private: int numerator, denominator; char sign;
I cannot get my function overloading the input operator for rational type objects to work.
lab9.cpp: In function ‘std::istream& operator>>(std::istream&, const rational&)’: lab9.cpp:186:20: error: invalid initialization of reference of type ‘std::istream& {aka std::basic_istream<char>&}’ from expression of type ‘rational’ return (inputFrac);
lab9.h
#include <iostream> using namespace std; class rational { public: rational(); rational(int a, int b);
I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..
i want to print Largest number from any 5 rows.Th number printed should be any one of the largest in the five rows of 2d arrays.I have created code for largest number in each row but how to pick and print them randomly?.
Code:
#include<conio.h> main( ) { int a,b,c,d,e,x; int arr[] = {a,b,c,d,e}; int Matrix[5][5] ={ /*Initializing array*/ 2,4,3,5,9, 6,8,2,2,10,
Basically i want to input a number for example 123456 and get back how many 7's are in the input number and also to print out that same number with stars in between like this *1*2*3*4*5*6*. Here is what i have so far:
#include <iostream> using namespace std; int countSeven(int x){ if(x == 7)return 1; int c = 0; while(x/10 > 9)c++; return countSeven(x/10)+1;
when i compile it does not do what i tell it it just tells me there are 0 7's in the input number no matter how many there really are...
fstream infile1(argv[1]); if(!infile1.is_open()) cout << "Could not open file"; else { char listNum; while(infile1.get(listNum)) cout << listNum; }
However, when I check for odd or even numbers it will check each and every number.
printed like this (partial list): 1 is odd 3 is odd 8 is even 9 is odd
But it should print: 138 is even 9 is odd
I tried using getline, but it keeps giving me the errors: invalid conversion from 'void*' to 'char**' invalid conversion from 'char' to 'size_t*' too few arguments to function 'ssize_t getline(char**, size_t*, FILE*)'
Here is the getline code, what am I doing wrong? I have tried switching things around, adding things. Just nothing works.
ifstream infile1(argv[1]); if(!infile1.is_open()) cout << "Could not open file"; else { char listNum; getline(infile1, listNum); cout << listNum; }
I created a richtextbox to input the text that I want to print, the command for printing which is the button and instead of printdialog box((PrintDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)) to be display, I created combobox which will display the available printers and then print.
Like this code bellow .
To get the available printers:
foreach (String printer in PrinterSettings.InstalledPrinters) { cbox.Items.Add(printer.ToString()); }
Now what I want to do is I will add some textbox to input the page number to be printed . For example the current pages in the richtextbox are 12pages when I'm going to run the program I will input in the textbox the page/s that I want like (3-7pages). How could it be ?
C programming, make it use a function call to print the smallest number? this is a program which prints out the smallest of three numbers within the main function that I was asked to write.Now the other question i am asked,5. Re-write the program, uses a function call to print the smallest number?
Code:
# include <stdio.h>
main() { int a,b,c; int temp, min; a = 100; b = 23; c = 5; }
I've written a program which takes a character string and then prints each character vertically so that for instance the string 123 can be written as 1 2 3
no what i need is for all the numbers from zero to the inputted number to print the numbers digits vertically but each number to be printed horizontally so that for instance an input of 11 prints
1 2 3 4 5 6 7 8 9 1 1 0 1
i've made it so that i can print all numbers up to the inputted number vertically; however, i am stuck with a method for making each number print horizontally as described above.
I'm working my way through some C exercises to get some practice and have hit a wall. I need to use a function to take a number, such as 1, and print out One.Here's what I've got so far:
Code: #include <stdio.h> int name(int n); char numberOne[] = "One"; int main(void) { int n; }
[code]...
However, when I run the code and enter "1" the only thing that gets printed to the screen is "(lldb)". I've tried changing it to doing it without variables and just printing "One" but that gave the exact same result.