in this quastion i just need to add the main. everything else is preaperd.
you dont need to understand what is in the fixtfloat.cpp
(i understand it but you dont need to understand it also for writing the main)
i just say that fixtfloat takes str and makes him to be float.
in the main that i need to write, i need to write function that its name is
"tester". i put in the tester function:
name, input (need to be str), output (need to be float).
the tester function calls to the preaperd function fixtfloat and give it the
input. after that i compare between what the function fixtfloat returnd me
and the output that tester function got. if they are equal so the tester
function return 1 else 0. i worte the main but it dont let me run it.
i sure that there are problems with the syntax and with the libary syntax - that i trying to fint for a lot of time.
if someone can help me, i will be very happy. thanks.
stdafx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
// The following macros define the minimum required platform. The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
// your application. The macros work by enabling all features available on platform versions up to and
// including the version specified.
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif
// stdafx.cpp : source file that includes just the standard includes
// fixtfloat.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
#pragma once
#include <iostream>
#include <tchar.h>
#include <ostream>
using namespace std;
#include <math.h>
float fix2float(char * n)
{
int ll =0;
while (n[ll] != 0x00)ll++;
ll -=1;
int js =0;
float f =0.0;
int sign =1;
float frac =0.1;
if (ll < 0)return 0.00; // like in empty chain
if ('-'==n[0]) // if the first ch is -
{ sign = -1;
js =1; // if there are - or +, js is 1, otherwise 0
}
if ('+' == n[0])js =1; // if the first ch is +
int jn = js; // like js: if there are - or +, jn will be 1, otherwise 0
for (int jk =js; jk <= ll;jk++) // if there are - or +, jk will move on the input from the second ch, otherwise from the first ch
{
jn =jk; // at first, if there are - or +, jn like jk, will start from the second ch and will be 1, otherwise it will start from the first ch and will be 0
if(46 == int(n[jk]))break;//dot constant // if we see dot we break
f=f*10+(int(n[jk])-48);//add binary number not character! // moving one place right and add the binary
}
if(jn == ll)return sign*f;//dot is the last character // in the previous loop we searched all the input and we found dot in the last ch
js = jn+1; //we got here if there is a dot in the middle of the chain. now js is the place after the dot
for (int lk = js;lk<=ll;lk++) // we search from the place after the dot until the end
{
f =f + frac*(int(n[lk])-48);
frac = frac*0.1;//as fraction part grows its multiplier decreases
}
return sign*f;
}
int tester (str * a, str * b, float c)
{
w = fix2float ( * b);
if (w==c) return 1
else return 0;
}
int main ()
{
int b;
b = tester ("empty chain","",0.0);
b = tester ("simple chain,"123",123.0);
b = tester ("chain starts with +","+4567",4567.0);
cout << "The result is " << b;
return 0;