Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,207,514 members, 7,999,296 topics. Date: Sunday, 10 November 2024 at 11:47 PM

Check In: Submit Your C++ Questions Lets Solve - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Check In: Submit Your C++ Questions Lets Solve (6096 Views)

Mybb Expert Needed: Please Check In Here / Please I Get This Error When Submit Form (notice: Undefined Index) (2) (3) (4)

(1) (2) (3) (Reply) (Go Down)

Re: Check In: Submit Your C++ Questions Lets Solve by 1stdami(m): 2:23pm On Jun 28, 2015
BlueMagnificent:


Sorry, there is noting like C++ console. What I believe you mean is writing and reading from the console which every other programming language does. And C++ is as much object oriented as java
well if u say so mayb we have different meaning for oop
Re: Check In: Submit Your C++ Questions Lets Solve by 1stdami(m): 2:24pm On Jun 28, 2015
jacob05:
hmmmm..enough arguments... I need a C++ solution.......
to compute wat
Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 3:52pm On Jun 28, 2015
BlueMagnificent:


Sorry, there is noting like C++ console. What I believe you mean is writing and reading from the console which every other programming language does. And C++ is as much object oriented as java
Boss Abi ooo.... Just ain't ready to push the argument ni ooo... How's the game project going?
Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 3:54pm On Jun 28, 2015
1stdami:
to compute wat
the question na
Re: Check In: Submit Your C++ Questions Lets Solve by BlueMagnificent(m): 6:09pm On Jun 28, 2015
jacob05:
Boss Abi ooo.... Just ain't ready to push the argument ni ooo... How's the game project going?

Its really going well, getting interesting day by day
Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 1:16am On Jun 30, 2015
Hmmm. Ok...

I need an elegant way using oop concepts to solve the below problem.... The program can accept any number of mixed fraction, fraction or whole numbers and operations to perform on them... It should follow mathematical rules in solving them .... The program should , in the end, print the values accepted "elegantly" and results..

www.nairaland.com/attachments/2566275_imag20251_jpeg289e6d9aae576e422a9704ae0757fd0e


CC pcguru1 1stdami BlueMagnificent seunthomas
Re: Check In: Submit Your C++ Questions Lets Solve by cotmag(m): 10:46pm On Jun 30, 2015
I installed a visual c++ program successfully few days ago but each time I tried to open the program, it will display the message: program can't open. Pls how can I resolve the problem?
Re: Check In: Submit Your C++ Questions Lets Solve by Nobody: 9:04am On Jul 01, 2015
jacob05:
Hmmm. Ok...

I need an elegant way using oop concepts to solve the below problem.... The program can accept any number of mixed fraction, fraction or whole numbers and operations to perform on them... It should follow mathematical rules in solving them .... The program should , in the end, print the values accepted "elegantly" and results..

www.nairaland.com/attachments/2566275_imag20251_jpeg289e6d9aae576e422a9704ae0757fd0e


CC pcguru1 1stdami BlueMagnificent seunthomas

Hi jacob working on it, though might be late to submit cuz of work but out of curiosity (3 1/2) how would that be inputted am assuming the method will take 7/2 as 3 1/2 will might be interpreted as 31 then / 2 my intention is to parse the text. interesting task will get back on this, but might be slow but this is interesting regardless. smiley

1 Like

Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 12:29pm On Jul 01, 2015
pcguru1:


Hi jacob working on it, though might be late to submit cuz of work but out of curiosity (3 1/2) how would that be inputted am assuming the method will take 7/2 as 3 1/2 will might be interpreted as 31 then / 2 my intention is to parse the text. interesting task will get back on this, but might be slow but this is interesting regardless. smiley
Thanks boss... I care less how inputs are accepted...you can use the values in the pix... All I need is the implementation
Re: Check In: Submit Your C++ Questions Lets Solve by 1stdami(m): 2:19pm On Jul 01, 2015
jacob05:
Thanks boss... I care less how inputs are accepted...you can use the values in the pix... All I need is the implementation

do you mean that u dont mind if i change this fractions to decimal also
Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 5:10pm On Jul 01, 2015
1stdami:


do you mean that u dont mind if i change this fractions to decimal also
No oooo...decimal ke...That'd defect the main purpose of the question
Re: Check In: Submit Your C++ Questions Lets Solve by trigar12(m): 6:52pm On Jul 01, 2015
1stdami:
Hello guys, you can submit your C++ question let solve it together or if you have any code that you want to debug you can post also. If you have problem with any other programming language lemme know also

I wanna learn c++ but all the ebooks I ve been reading are always getting me confused ... Can you recommend a really good one for me please?

I really wanna learn this language

angry cry
Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 8:14pm On Jul 01, 2015
trigar12:


I wanna learn c++ but all the ebooks I ve been reading are always getting me confused ... Can you recommend a really good one for me please?

I really wanna learn this language

angry cry
C++ problem analysis to program design...book is good
Re: Check In: Submit Your C++ Questions Lets Solve by 1stdami(m): 9:48am On Jul 02, 2015
trigar12:


I wanna learn c++ but all the ebooks I ve been reading are always getting me confused ... Can you recommend a really good one for me please?

I really wanna learn this language

angry cry


i will advice u watch videos on youtube rather dan those books it is better for beginners you can search "bucky tutorials" on youtube

1 Like

Re: Check In: Submit Your C++ Questions Lets Solve by nembudziya(m): 12:10pm On Jul 04, 2015
1stdami:

allright am all ears
what is a scope operator :: and how is it used,thank you.
Re: Check In: Submit Your C++ Questions Lets Solve by nembudziya(m): 12:12pm On Jul 04, 2015
codemarshal08:

Bro IMO, there is no direct way to output to a printer in c++. Printing is an OS-Dependent Operation.
ok,thanks but what OS is used by the handheld portable printers
Re: Check In: Submit Your C++ Questions Lets Solve by nembudziya(m): 12:15pm On Jul 04, 2015
bowofolu:
@nembudziya
Run the code below in command prompt. If it prints the text file, you will be able to use it in your c++ code.

notepad /p your_file.txt
ok, thank you. Suppose i return 0,what part of the code you suggest i put the command
Re: Check In: Submit Your C++ Questions Lets Solve by nembudziya(m): 12:19pm On Jul 04, 2015
jacob05:
shocked shocked shocked....are you shitin me? C++ is even the best to solve it.
thats right.most programs running on windows were written in c++.

1 Like

Re: Check In: Submit Your C++ Questions Lets Solve by codemarshal08(m): 3:53pm On Jul 04, 2015
nembudziya:
ok,thanks but what OS by the handheld portable printers
could you please rephrase your question, can't really understand it
Re: Check In: Submit Your C++ Questions Lets Solve by moderatorr1: 4:30am On Jul 05, 2015
There is a healthy c++ tutorial here if you need more help : http://braintem.org/series/view/43991/
Re: Check In: Submit Your C++ Questions Lets Solve by nembudziya(m): 7:25am On Jul 05, 2015
codemarshal08:

could you please rephrase your question, can't really understand it
sorry abt dat, iv modified the qsn.
Re: Check In: Submit Your C++ Questions Lets Solve by gmus: 8:33am On Jul 05, 2015
nembudziya:
i want to know how to save, retrieve and print a receipt from a portable printer like they use for parking automobiles.

solution.

1. Declare an ofstream object
2. open d object using d printer name in place of a filename.

3. write to d printer as u would write to a file.

In general to write to a printer, replace d filename/fileapath to a printername/printerpath in a file writing program.



So a general solutn is this:
Write program that writes to file but use the printer name/path in place filename/path.



POST EDIT;
Here is a good example:


http://www.dreamincode.net/forums/topic/43225-c-program-to-use-console-for-input-and-printer-for-output/
Re: Check In: Submit Your C++ Questions Lets Solve by nembudziya(m): 12:45pm On Jul 05, 2015
gmus:


solution.

1. Declare an ofstream object
2. open d object using d printer name in place of a filename.

3. write to d printer as u would write to a file.

In general to write to a printer, replace d filename/fileapath to a printername/printerpath in a file writing program.



So a general solutn is this:
Write program that writes to file but use the printer name/path in place filename/path.



POST EDIT;
Here is a good example:


http://www.dreamincode.net/forums/topic/43225-c-program-to-use-console-for-input-and-printer-for-output/
hmmmmmm..........i am astounded. Whats a console, though. Guy, i think you also have to help me on friendship and inheritance cos its one area i'd to master, plus pointers, wow, especially the *this pointer. Hope to hear from you concerning this one matter. Thanks in advance.
Re: Check In: Submit Your C++ Questions Lets Solve by codemarshal08(m): 1:49pm On Jul 05, 2015
nembudziya:
hmmmmmm..........i am astounded. Whats a console, though. Guy, i think you also have to help me on friendship and inheritance cos its one area i'd to master, plus pointers, wow, especially the *this pointer. Hope to hear from you concerning this one matter. Thanks in advance.
It seems you are a beginner programmer. I will advice you get a good c++ book as Jacob Suggested. These things are not as complex as you think.
C++ is not a language u rush over. just take your time and learn the damn Beast !

1 Like

Re: Check In: Submit Your C++ Questions Lets Solve by gmus: 3:55pm On Jul 05, 2015
nembudziya:
hmmmmmm..........i am astounded. Whats a console, though. Guy, i think you also have to help me on friendship and inheritance cos its one area i'd to master, plus pointers, wow, especially the *this pointer. Hope to hear from you concerning this one matter. Thanks in advance.


See this:
https://en.m.wikipedia.org/wiki/Console_application


I know dt the ofstream object is a stream. it is like an interface btw a program and and a device. When u write with ofstream u are not writng to a devicr. You are writing to a stream. Files and printers are examples of devices.



POST EDIT:
Download and read ; C++: The Complete Reference by Hebert Sheildt 4th Edition.

U can also check my post in my main nairaland account - mnairaland
Re: Check In: Submit Your C++ Questions Lets Solve by gmus: 4:18pm On Jul 05, 2015
1stdami:
well if u say so mayb we have different meaning for oop

Put simply object oriented programming is an approach to programming that uses classes and objects.
1stdami:
well if u say so mayb we have different meaning for oop

Put simply object oriented programming is an approach to programming that uses classes and objects.
1stdami:
well if u say so mayb we have different meaning for oop

Put simply object oriented programming is an approach to programming that uses classes and objects.

A class is a definition of an object. It is an abstraction. it does not exist. A class specifies d form that an object must take when it is created. An object is a physical realization of a class.
Re: Check In: Submit Your C++ Questions Lets Solve by gmus: 4:33pm On Jul 05, 2015
nembudziya:
i want to save, output from cout<<, and retrieve the output anytime, i need to print a receipt.

Files(i.e. disk),console, and printer are examples of devices.

cout writes to stdout by default which is d console. It can be redirected to write to any other output device.

If u wish to write to a device and retrieve later dn dt device must neccesatily be a file.

1 Like

Re: Check In: Submit Your C++ Questions Lets Solve by gmus: 4:45pm On Jul 05, 2015
1stdami:
i am talking abt c++ console here ...but java can perform the operation easier dont u tink so


Simply put. A console can be described as a non-graphical screen writing environment as opposed to a window which is graphical.

1 Like

Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 9:31pm On Jul 05, 2015
Guess I'd proffer my (temporal) solution.


CC pcguru1 1stdami BlueMagnificent seunthomas
Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 9:33pm On Jul 05, 2015
fraction.h


/*
* File: fraction.h
* Author: pyjac
*
* Created on July 5, 2015, 7:45 PM
*/

#ifndef FRACTION_H
#define FRACTION_H

#include <iostream>

using namespace std;

class Fraction {
public:
/**
Constructs a fraction with numerator 0 and denominator 1
*/
Fraction();

/**
Constructs a fraction with numerator t and denominator 1
@param t the numerator for the fraction
*/
Fraction(int t);

/**
Constructs a fraction with given numerator and denominator
@param t the initial numerator
@param b the initial denominator
*/
Fraction(int t, int b);

/**
Constructs a fraction with given numerator and denominator
@param wn the initial whole number
@param t the initial numerator
@param b the initial denominator
*/
Fraction(int wn,int t, int b);

/**
Returns the numerator
@return the numerator value
*/
int numerator() const;

/**
Returns the denominator
@return the denominator value
*/
int denominator() const;

/**
updates a fraction by adding in another fraction value
@param right the fraction to be added
@ return the updated fraction value
*/
Fraction& operator+=(const Fraction& right);

/**
increment fraction by 1
*/
Fraction& operator++(); // Prefix form
Fraction operator++(int unused); // Postfix form

/**
converts a fraction into a floating-point value
@return the converted value
*/
operator double() const;

/**
compare one fraction value to another
result is negative if less than right, zero if equal, and
positive if greater than right
@param right the fraction to be compared against
*/
int compare(const Fraction& right) const;
private:
/**
place the fraction in least common denominator form
*/
void normalize();
/**
compute the greatest common denominator of two integer values
@param n the first integer
@param m the second integer
*/
int gcd(int n, int m);
int top;
int bottom;
};

Fraction operator+(const Fraction& left, const Fraction& right);
Fraction operator-(const Fraction& left, const Fraction& right);
Fraction operator*(const Fraction& left, const Fraction& right);
Fraction operator/(const Fraction& left, const Fraction& right);
Fraction operator-(const Fraction& value);

bool operator<(const Fraction& left, const Fraction& right);
bool operator<=(const Fraction& left, const Fraction& right);
bool operator==(const Fraction& left, const Fraction& right);
bool operator!=(const Fraction& left, const Fraction& right);
bool operator>=(const Fraction& left, const Fraction& right);
bool operator>(const Fraction& left, const Fraction& right);

ostream& operator<<(ostream& out, const Fraction& value);
istream& operator>>(istream& in, Fraction& r);

#endif

Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 9:36pm On Jul 05, 2015
fraction.cpp

/*
* File: fraction.cpp
* Author: pyjac
*
* Created on July 5, 2015, 7:45 PM
*/

#include "fraction.h"
#include <cassert>
#include <stdexcept>

int Fraction::gcd(int n, int m)
{
// Euclids Greatest Common Divisor algorithm.
assert((n > 0) && (m > 0));
while (n != m)
{
if (n < m)
m = m - n;
else
n = n - m;
}
return n;
}

Fraction::Fraction(int t, int b) : top(t), bottom(b)
{
normalize();
}

Fraction::Fraction(int wn,int t, int b): top( (wn * b) + t), bottom(b){
normalize();
}

Fraction::Fraction() : top(0), bottom(1) { }

Fraction::Fraction(int t) : top(t), bottom(1) { }

int Fraction::numerator() const
{
return top;
}

int Fraction::denominator() const
{
return bottom;
}

void Fraction::normalize()
{
// Normalize fraction by
// (a) moving sign to numerator
// (b) ensuring numerator and denominator have no common divisors
int sign = 1;
if (top < 0)
{
sign = -1;
top = - top;
}
if (bottom < 0)
{
sign = - sign;
bottom = - bottom;
}
assert(bottom != 0);
int d = 1;
if (top > 0) d = gcd(top, bottom);
top = sign * (top / d);
bottom = bottom / d;
}

Fraction operator+(const Fraction& left, const Fraction& right)
{
Fraction result(left.numerator() * right.denominator()
+ right.numerator() * left.denominator(),
left.denominator() * right.denominator());
return result;
}

Fraction operator-(const Fraction& left, const Fraction& right)
{
Fraction result(left.numerator() * right.denominator()
- right.numerator() * left.denominator(),
left.denominator() * right.denominator());
return result;
}

Fraction operator*(const Fraction& left, const Fraction& right)
{
Fraction result(left.numerator() * right.numerator(),
left.denominator() * right.denominator());
return result;
}

Fraction operator/(const Fraction& left, const Fraction& right)
{
Fraction result(left.numerator() * right.denominator(),
left.denominator() * right.numerator());
return result;
}

Fraction operator-(const Fraction& value)
{
Fraction result(-value.numerator(), value.denominator());
return result;
}

int Fraction::compare(const Fraction& right) const
{
return numerator() * right.denominator() -
denominator() * right.numerator();
// return the numerator of the difference
}

bool operator<(const Fraction& left, const Fraction& right)
{
return left.compare(right) < 0;
}

bool operator<=(const Fraction& left, const Fraction& right)
{
return left.compare(right) <= 0;
}

bool operator==(const Fraction& left, const Fraction& right)
{
return left.compare(right) == 0;
}

bool operator!=(const Fraction& left, const Fraction& right)
{
return left.compare(right) != 0;
}

bool operator>=(const Fraction& left, const Fraction& right)
{
return left.compare(right) >= 0;
}

bool operator>(const Fraction& left, const Fraction& right)
{
return left.compare(right) > 0;
}

ostream& operator<<(ostream& out, const Fraction& value)
{
out << value.numerator() << "/" << value.denominator();
return out;
}

istream& operator>>(istream& in, Fraction& r)
{
int t, b;
// Read the top
in >> t;
// If there is a slash, read the next number
char c;
in >> c;
if (c == '/')
in >> b;
else
{
in.putback(c);
b = 1;
}
r = Fraction(t, b);
return in;
}

Fraction::operator double() const
{
// convert numerator to double, then divide
return static_cast<double>(top) / bottom;
}

Fraction& Fraction::operator++()
{
top += bottom;
return *this;
}

Fraction Fraction::operator++(int unused)
{
Fraction clone(top, bottom);
top += bottom;
return clone;
}

Fraction& Fraction::operator+=(const Fraction& right)
{
top = top * right.denominator() + bottom * right.numerator();
bottom *= right.denominator();
normalize();
return *this;
}


REF : http://www.math.ucla.edu/~wittman/10a.1.10w/ccc/ch17/index.html
Re: Check In: Submit Your C++ Questions Lets Solve by jacob05(m): 9:38pm On Jul 05, 2015
main.cpp


/*
* File: main.cpp
* Author: pyjac
*
* Created on June 30, 2015, 1:51 AM
*/

#include <cstdlib>
#include <iostream>
#include "fraction.h"
#include <cassert>

using namespace std;


/*
*
*/
int main(int argc, char** argv) {

Fraction a(3,1,2);
Fraction b(2,3);
Fraction c(4,5);
Fraction d(4);
Fraction e(6,2);
Fraction f(9,6,cool;

Fraction g = a + b - c * d / e -f;
cout << "Solution: " << g <<endl; // -133/20
return 0;
}

www.nairaland.com/attachments/2566275_imag20251_jpeg289e6d9aae576e422a9704ae0757fd0e

REF : http://www.math.ucla.edu/~wittman/10a.1.10w/ccc/ch17/index.html


CC pcguru1 1stdami BlueMagnificent seunthomas

(1) (2) (3) (Reply)

(revealed) So Mark Zuckerberg Is Not That Good At Coding/programming! / [MOD] PHP WORKOUTS - String Manipulation 1 / Download Asp.net Mvc 5 Essential Training Video Tutorial

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 62
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.