Problem with graph.h

I use Dev-C++ 5.11

Im reading Programming Principles and practice using c++.

First problem i had was unable to use std_lib_facilities. also Graph.h and Simple_window.h. I did alot of thing but seem like this program im using, use different code completely.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include "std_lib_facilities.h"
using namespace std;

int main()
{
	cout << "Please enter your first name: ";
	string first_name;
	cin >> first_name;
	cout << "\n";
	cout << "Hello, " << first_name << "!\n";
	cout << "\n";
	cout << "Please enter your Last name: ";
	string last_name;
	cin >> last_name;
	cout << "\n";
	cout << "So your name is, " << first_name << " " << last_name << "!\n";
	return 0;
}
> First problem i had was unable to use std_lib_facilities. also Graph.h and Simple_window.h

Download them from here:
http://stroustrup.com/Programming/PPP2code/

Start with just std_lib_facilities.h, that is all you need for the first several chapters. http://stroustrup.com/Programming/PPP2code/std_lib_facilities.h
Thanks for the site, it help a lot for the future.

But I'm a truly newbie.

I tried to add them in Dev C++ tool > compiler opinion then directories tab, i put them in all tab binaries, libraries, c includes, c++ includes. I compiler and run. the error still pop up. [error] Simple_window.h: No such file or directory.

Next method I tried, went in Dev C++ files directly. program file (x86) > Dev-Cpp > MinGW64 > include and save the files i copied from the site.

I copied and paste them in notepad, then saved as .h or .cpp followed the title site gave. it changed to C Header File or CPP File. I assume its right.

Nothing work right still. I'm sorry for being mega noob. thanks

edit: Seem like std_lib_facilities.h worked.
I would like to understand what exact i need to get Simple_window.h to work. thanks again
Last edited on
> would like to understand what exact i need to get Simple_window.h to work. thanks again

You need to install a library (fltk) for that to work.

You don't need "Simple_window.h" at all for the first dozen or so chapters
(IIRC, all that you would need is "std_lib_facilities.h").

By the time you reach the part of the book where "Simple_window.h" is actually required, you would be a lot more familiar with include files and the tool-chain. You can install fltk at that point.
Thank you for your help. I'll be here more often. I'm really interest in this programming.
Im trying to get some trial to work. But seem I cant get it.

Trial: Get the "name and age" example to run. Then, modify it to write out the age in months: read the input in years and multiply (using the * operator) by 12.

I understand I need to have put age then * 12 to make it in month.
I must be awful at programming to not able to get in third chapter.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <std_lib_facilities.h>

int main()

{
	std::cout << "Please enter your name and age. ";
	string first_name;
	int age;
	int year;
	age * 12;
	std::cin >> year;
	std::cin >> first_name;
	std::cin >> age;
	std::cout << "\n";
	std::cout << "Your name is " << first_name << " " << "(age " <<age<<")\n";
	std::cout << endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream> // "stdlib_facilities.h"

int main()
{
    std::cout << "Please enter your first name and your age in years.\n" ;

    std::string first_name ; // variable to hold the name
    std::cin >> first_name ; // read the name (a string)

    int age_in_years = 0 ; // variable to hold the age
    std::cin >> age_in_years ; // read the age (an integer)

    // age in months is age_in_years multiplied by 12
    // multiply age_in_years by 12 and store the result in the variable age_in_months
    int age_in_months = age_in_years * 12 ;

    // print out name and age in months
    std::cout << "Your name is " << first_name << " (age " << age_in_months <<" months)\n" ;
}
Last edited on
Ah, its exact what i was suppose to do. I went ahead and research and copied some line from other. I guesses and it were right. But its different, and why does it work same?

edit: Is it possible to make something like this =

example int 1 = january
I know int 1 is not right, but its what i would like to know.

i wish to put an mm/dd/yyyy into word.

08/05/1987
command reply in
August 5, 1987
or is it too early for me to attempt?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <std_lib_facilities.h>

int main()

{
	std::cout << "Please enter your name and age. ";
	string first_name;
	int age;
	std::cin >> first_name;
	std::cin >> age;
	age * 12;
	int result;
	result = age * 12;
	
	std::cout << "\n";
	std::cout << "Your name is " << first_name << " " << "(age in month " <<result<<")\n";
	std::cout << endl;
}
Last edited on
> age * 12; // line 11

This does not do anything meaningful (multiply age by 12 and discard the result).


> i wish to put an mm/dd/yyyy into word.

Put it into three different integers: month, day and year

> or is it too early for me to attempt?

If you have come across selection statements: for example if( month_number == 3 ) month_string = "March" ;
attempt it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream> // std_lib_facilities.h
#include <string>

int main()
{
    std::cout << "Please put your birthday in mm/dd/yyyy \n";

	int month;
	int day;
	int year;
	char slash ; // to read the separator

	std::cin >> month; // read the month
	std::cin >> slash; // read the '/'
	std::cin >> day; // read the day
	std::cin >> slash; // read the '/'
	std::cin >> year; // read the year

	std::string month_name = "invalid month" ;

	// if the condition ( month === 1 ) evaluates to true (if the entered month is 1)
	if( month == 1 ) month_name = "January"; // then set month_name to "January";

	if( month == 2 ) month_name = "February";
	// and so on, up to December

    std::cout << "Your birthday is: " << month_name << ' ' << day << ", " << year << '\n' ;
}

http://coliru.stacked-crooked.com/a/830927b5be80ba7c
Thanks a lot JLBorges, that helped. I got other help, made one alone for month. I understand how to add more now. ^ ^
Hi Soulworld05,

I am reading the book "Programming Principles and practice using c++" too. Have you reached chapter 6.7?
I got stuck over there, since I cannot find the file calculator01.cpp anywhere. I need this file to follow the rest of book.

I appreciate if you have any idea and share it with me.

BTW, I am a beginner in C++ and I've started with this book. Maybe we can share our information while reading the book. I believe it helps a lot to learn better and faster.

Cheers,
P.
Is this what you are looking for?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
// This is example code from Chapter 6.7 "Trying the second version" of
// "Software - Principles and Practice using C++" by Bjarne Stroustrup
//

/*
	This file is known as calculator02buggy.cpp

	I have inserted 5 errors that should cause this not to compile
	I have inserted 3 logic errors that should cause the program to give wrong results

	First try to find an remove the bugs without looking in the book.
	If that gets tedious, compare the code to that in the book (or posted source code)

	Happy hunting!

*/

http://www.stroustrup.com/Programming/calculator02buggy.cpp
Thank you JLBorges! But it's not. This version includes 5 errors which I am not able to remove some of them. Actually this is an exercise for the time I finish this chapter.
Hi Parisa,

I'm not far in the book. Currently trying to remember all words by typing them often. I want to get habit of typing them before move on. I'm on 3.7 currently, JLBorges are really at helping.
OK, thank you :)
Topic archived. No new replies allowed.