I have to develop an address book for contacts, and it has to be able to add contacts, delete them, and show them all while implementing dynamic memory allocation. I'm thinking I should be going with an array of structures, but I'm not sure how to handle that in the context of this problem. I realize deleting them will most likely end up just being me using the free function. i'm thinking I should show all the contacts with a for loop, but say u deleted contacts, and those memory spaces were now absent, how would I go about it because the looping structure would be flawed wouldn't it.
This program is an address book where you caan add/view entries. I'm having a problem printing out entries. Why the information isn't getting saved into the structure array?
Code: #include <iostream> #include <string> using namespace std; struct contactinfo
the program is of an address book. the syntax is all fine, and the initial menu of options does show up. but once you punch in the cin, the program just stops.
My address book will be simple, and the thing's that I'm expecting to use in it are :
Pointers, Linked Lists Malloc Structs Typedefs Makefile, header file Putting functions into different program files
I have started the program trying to create a struct, and getting it working with a couple of entries before going onto user input and splitting it up.
Code:
#include <stdio.h> #include <stdlib.h> int main(void) { // Struct type address book. Just a name, a number and a pointer
[Code] .....
I'm a bit lost at this point... My knee jerk thought is to create a for loop, and cycle through the list.
I'm not sure how this would apply to this though? Without using the familiar type of print loop such as :
Code: for (i = 0; ;i++) { printf("%i ", array[i]; }
I'm thinking that I need to create a temporary struct that can be used to assign the value of the next struct in the list, and then somehow print from that....
I'll try and write the logic out :
while temp != NULL (The last node value is assigned NULL to show us where the end of the list is)
create a temporary pointer that can be used to keep track of where we are in the list.
print out the current entry name and number
then assign the temp pointer value to the * next of the current struct. So if we are in entry1 the *next should be the address of entry 2.
Print out entry 2 name and number, assign entry 2 next to the temp value.
I am currently developing an application for backing-up cellphone contacts to a computer. The problem I am having is that I need my app to auto detect a cellphone (i.e. regardless of the Make and Model) when plug onto a computer and with a single click of a button "Backup" the app must backup all contact on the cellphone onto to the computer. How can I get my app to auto-detect a plugged cellphone and how can I go about reading the cellphone's contacts.
In this assignment the student should develop a month calendar by designing a class called calendarType . This class uses two other classes (dateType and dayType) as described below:
1. dayType Class: This class has been designed by students in Lab1 exercises. Referee to it. 2. dateType Class: This class is designed and implemented to keep track of data. This class has been provided it to you. Study it first then add definitions and implementations of the following operations to this class:
- Test whether the year is a leap year. Leap year is identified by 3 criteria : - The year is evenly divisible by 4; - If the year can be evenly divided by 100, it is NOT a leap year, unless; - The year is also evenly divisible by 400. Then it is a leap year. - Return the number of days in the month. For example, if the date is 12/3/2014, the number of days to be returned is 31 because there are 31 days in March. - Return the number of days passed in the year. For example, if the date is 18/3/2014 the number of days passed is 77. Note that the number of days returned also includes the current day. - Return the number of days remaining in the year. For example, if the date is 18/3/2014 , the number of days remaining in the year is 288. - Calculate the new date by adding a fixed number of days to the date. For example, if the date is 18/3/2014 and the days to be added are 25, the new date is 12/4/2014.
To print monthly calendar using calendarType class, you must know the first day of the month and the number of the days in that month. Thus, you must store the first day of the month, which is in the form of dayType and the month and the year of the calendar. Clearly, the month and the year can be stored as an object of the form dateType by setting the day component of the date to 1, and the month and year as specified by user.
Design the class calendarType so that the program print a calendar for any month starting 1/1/ 1500 which is Monday. To calculate the first day of a month, you can add the 2 appropriate days to Monday of January 1, 1500. For this class identify and implement the following operations:
- Determine the first day of the month for which the calendar will be printed. Call this operation firstDayOfMonth. - set/get month. - set/get year. - Print calendar for particular month. - Add the appropriate constructors to initialize the member variables. - Write a test program to print the calendar for either a particular year or a particular month.
I am trying to develop a function which prints a binary tree using post-order traversal (left, right, root) but I am experiencing some troubles. The code is compiled but when I run the program it crashes right before printing the post-order traversal.
Below you can find my code and the output from debugging.
Code: /** Program which represents a Binary Search Tree and is modified with the following functions: - smallest() - member function which searches for the smallest element in the tree. - preorder() - member function which prints the tree nodes using pre-order traversal - postorder() - member function which prints the tree nodes using post-order traversal (to be completed) */ #include <iostream> #include <cstdlib> #include <string> using namespace std; class TreeNode { public:
[code]...
This is from the debugger log:
Child process PID: 5720 At C:Program Files (x86)CodeBlocksProjectsTestmain.cpp:316 At C:Program Files (x86)CodeBlocksProjectsTestmain.cpp:317 At C:Program Files (x86)CodeBlocksProjectsTestmain.cpp:318 At C:Program Files (x86)CodeBlocksProjectsTestmain.cpp:319 Program received signal SIGSEGV, Segmentation fault. At C:Program Files (x86)CodeBlocksProjectsTestmain.cpp:279
I am trying to make a grade book and using a vector to get the grades. I am getting errors all over and I figured this would happen because this is the first time I ever used vectors.
I'm writing a program that uses the readline() function that comes in the Unix Network Programming book, when I use telnet to connect to my server the function reads the input perfectly displaying the username as the user types it in. However, when using a telnet client called syncterm it accepts the user input but does *not* echo it on the screen and I can't figure out why.
So I was asked to create a C++ program that will ask the user to input 5 books with the ISBN, Title of the book and author/s. It will ask for 3 authors, if the book has only one author, you should leave "author 2 and author 3" blank and display only one author. Thing is... I'm having a problem with the if else condition at the last part of my program. I cant seem to make it work.
#include <iostream> #include <cstring> #define SIZE 5 using namespace std; int i;
So I obviously can't take the address of a bitfield, but is there a way to get the address of the field holding the bitfield? What I'm trying to do is find the address of the parent field of a bitfield in a class. For example
Code: class Foo { public: int a; int b : 4; int c : 28; [Code] ....
My goal is to get the offset address of the int storing c in class Foo. But offsetof uses the address of c, so I get a compile error since c is a bitfield. What I wanted as output from the above would be "4", since an int is 4 bytes (on my system). So the int holding both b & c starts 4 bytes from the start of the Foo class. Is there any way to do this in c/c++?
I've run across this issue before, but for the like of me, I can't figure out what keeps causing it. The problem compiles and runs as expected; however in the salaried object (Employee #1 in main.cpp) the console displays the number of vacation days as -858993460 instead of the value entered.
The parent Employee class is abstract with calculatePay() and displayEmployee() being pure virtualls and with a Benefits, Salaried, and Hourly class derived from it.
The Salaried displayEmployee() and the portion of the Main.cpp that contains the salaried object follows. What causing this?
I've got a problem with a piece of code that it doesn't seem to work anymore.
Code: #include <stdio.h> #include <conio.h> main () {
[Code] ..... i
I chose a to be 5 and it displays the following:
"Type a value for a: 5 5 in octal is: 5 5 in hexadecimal is: 5
Process returned 23 <0x17> execution time : 1.031 s".I first saw this when trying to display the address of a pointer. Am i missing something? I used to run this code on dev-c++ successfully but after a day or so of practice, it's not working anymore. I switched from dev-c++ to code blocks.
So im trying to parse a string into a Ip Address but i have a problem, the IPAddress.Parse method only works for ipv4 address's how do i parse ANY Ip address into a string, if i use the IPaddress.Parse method on my public(remote) IP it throws an exception but on ipv4 local ip it doesn't how do i parse ANY ip address the user inputs as a string as an Ip Address?
I'm using the SDL library and trying to match the C++11 standards... Anyway, I thought about a vector where I store all the addresses of game instances, so I can access them anytime... I tried with this function:
Where "Instance" is the 'parent' class of various child classes like the player. So, if I have to search the existing of a thing in my game, I should check if the address references to an instance of class. How can I do this?
When this programs runs it displays odd symbols for the address of the character. This is only part of the program, I took out the parts that already work.
#include <iostream> using namespace std; char again;
I'd like a function to return either a value or the address of that value by the users input. So he can call the function like:
function("adress") - gets an adress, or function("value") - gets the value
I've tried both function overloading and templates, but none of them worked. He might input a character for the address and an int for the value... but...
Another strange thing that i observed is that the value returned by the function below is 0, so the output is address 0.