Home » C++ ProgrammingRSS

Help with this code

 

hello this code is for some reason is not running correctly in 2008 Express edition i am studying out of a book or i am missing something. It calls <iopmani.h> and <apstring.h>  and it cannot find those directories. here is the code and the output:

 

// average.cpp : main project file.
//This program reads a student's name and
//Three scores and displays the average
#include "stdafx.h"
#include <iostream>
#include <iomanip.h>
#include "apstring.h"
using namespace std;


int main() {

    int score1, score2, score3;

    double average;
    apstring last_name;

    cout << "Enter the student's last name and press Enter: ";
    cin >> last_name;
    cout << "Enter the first score and press Enter: ";
    cin >> score1;
    cout << "Enter the second name and press Enter: ";
    cin >> score2;
    cout << "Enter the third name and press Enter: ";
    cin >> score3;
    average = (score1 + score2 + score3) / 3.0;
    cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2);
    cout << "The average score for " << last_name;
    cout << " is " << average << end1;
    return 0;
}

Output:

------ Build started: Project: average, Configuration: Debug Win32 ------
Compiling...
average.cpp
.\average.cpp(6) : fatal error C1083: Cannot open include file: 'iopmani.h': No such file or directory
Build log was saved at "file://c:\Users\Kaleb G.Berry\Documents\Visual Studio 2008\Projects\average\average\Debug\BuildLog.htm"
average - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

1. I already tried fixing the headers like iomanip.h still it don't seem to work in ( ) or " "

this applies also to the apstring header which it is not reading. Since it cant do that it is not reading apstring as a var and i cant declare my var last_name.

 

7 Answers Found

 

Answer 1

hello this code is for some reason is not running correctly in 2008 Express edition i am studying out of a book or i am missing something. It calls <iopmani.h> and <apstring.h> and it cannot find those directories. here is the code and the output:
 
// average.cpp : main project file.
//This program reads a student's name and
//Three scores and displays the average
#include "stdafx.h"
#include <iostream>
#include <iomanip.h>
#include "apstring.h"
using namespace std;
iomanip.h is an obsolete header. It should be
 
#include <iomanip>
 
I'm not sure about apstring.h; does your book not explain about this?
 
But I don't think you need it. Just use std::string instead of apstring.
 
#include <string>
 
string last_name;
 
Note also that is is endl, not end1 (it means endline).
 
 

Answer 2

When i tried fixing the iomanip header it still did not work,

i read about apstring in the book it says

it is used to declare string varibles and manipulate them with operatiions such as input (>>) and operators concatention +.

i have many books for C++ this is one one those big theory books, and i am not sure if it is correct because it was made in1998, the other books i have teach C++ and there programs work real nice and they tell you how they work, but i am not sure they teach everything about what that certain class, header, etc can do like this one. Do i really need a book that teachs like bunch of theory and programming or should i read one that is more accurate programs  up to date, and less in depth with the meaning

 

Answer 3

O, ok i did apstring in Google. It on Dreamincode.net said this:

apstring is not a standard set of files...it is used specifically for teaching certain courses...there are numerous variations. You may have to get the specific variations you need from your school.

 

this means that i have to set files on my computer that school classes has to make apstring work and might as well study in the other books rather than this big text book.

 

Answer 4

When i tried fixing the iomanip header it still did not work,
 
i read about apstring in the book it says
 
it is used to declare string varibles and manipulate them with operatiions such as input (>>) and operators concatention +.
 
i have many books for C++ this is one one those big theory books, and i am not sure if it is correct because it was made in1998, the other books i have teach C++ and there programs work real nice and they tell you how they work, but i am not sure they teach everything about what that certain class, header, etc can do like this one. Do i really need a book that teachs like bunch of theory and programming or should i read one that is more accurate programs up to date, and less in depth with the meaning
I'm not quite sure what you are saying or asking here, but the following version of your code compiles and runs correctly:
 
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
 
using namespace std;
 
int main() {
 
    int score1;
    int score2;
    int score3;
    double average;
    string last_name;
 
    cout << "Enter the student's last name and press Enter: ";
    cin >> last_name;
    cout << "Enter the first score and press Enter: ";
    cin >> score1;
    cout << "Enter the second score and press Enter: ";
    cin >> score2;
    cout << "Enter the third score and press Enter: ";
    cin >> score3;
    average = (score1 + score2 + score3) / 3.0;
    cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2);
    cout << "The average score for " << last_name;
    cout << " is " << average << endl;
    return 0;
}
 
You do not need to use apstring class, and I'm really not sure why your book suggests using it.
 
 

Answer 5

The AP (Advanced Placement) classes were used in the past
by College Board members' Computer Science courses. They
are no longer used in the Board examinations, and are an
old implementation which has not been updated in many years.

It would be far better to learn the STL/SCL classes now.
However, if you want to experiment with them while doing
the exercises from an old textbook - or see how to implement
such classes - you can download them from here:

http://mathbits.com/mathbits/compsci/download.htm

- Wayne
 

Answer 6

>When i tried fixing the iomanip header it still did not work,

Note that vague references to something not working are
usually not adequate for getting help. Always be very
specific, and post examples of errors and the source code
which caused them.

- Wayne
 

Answer 7

 

Hi,

 

I'm very interested your issue, did you solve your problem?

If so please share the solution with us and mark the right answers.

If not please let me know.

 

Have a nice day!

Jesse

 
 
Search for  Help with this code
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter