I want it to store the integers as bits so that I am move them over and store them farther down the row as more numbers are added, but instead each new number is being added to the previous and I'm just getting a larger integer. Is this even a feasible way to store integers within an integer?
I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet
The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.
So I'm supposed to write a code that asks a user for a string and then displays the hex, decimal, and binary code for each individual letter and then tells the user how many bits in binary were 1. For example: Enter a line of text: Hello
The ASCII code for 'H' is 0x48 in hex, 72 in decimal, or 01001000 in binary, 2 bits were set. The ASCII code for 'e' is 0x65 in hex, 101 in decimal, or 01100101 in binary, 4 bits were set. The ASCII code for 'l' is 0x6c in hex, 108 in decimal, or 01101100 in binary, 4 bits were set. The ASCII code for 'l' is 0x6c in hex, 108 in decimal, or 01101100 in binary, 4 bits were set. The ASCII code for 'o' is 0x6f in hex, 111 in decimal, or 01101111 in binary, 6 bits were set.
So far I've got a code that will display the binary bit pattern by shifting a mask and testing for a 1 or 0. The problem is I can't figure out how to make it so the 1's and 0's get put into a single integer rather than just printing out. I hope that makes sense. Here's my whole code.
Code:
#include<stdio.h> main () { int i; char input; printf ("Enter ........: "); scanf ("%c", &input); for (i = 1; i <= 8; i++)
I have an assignment where I have to design, implement, and test a class for storing integer arrays "safely". I do not know how to set up the destructor.
The goal of this programming assignment is to give students practice defining and using classes. In particular, students are required to design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.
In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:
constructor - to initialize the object. copy constructor - to copy an object. destructor - to delete the object. set - allow the user to set a value of the array at a particular location. get - allow the user to get a value of the array at a particular location. print - print out the array. add - add the elements of one array to another. subtract - subtract the elements of one array from another.
The purpose of your main program "main.cpp" is to demonstrate that all of the methods above work properly. You should have at least one call to each of the methods, and print out the array as needed to show that the operations are performing correctly.
"SafeArray.h":
#ifndef SAFEARRAY_H #defineSAFEARRAY_H class Safe { private: // Declare variables to store A, B and C
I am currently stuck on what I should do next in a program I am working on. These are my instructions:
Design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.
In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:
constructor - to initialize the object. copy constructor - to copy an object. destructor - to delete the object. set - allow the user to set a value of the array at a particular location. get - allow the user to get a value of the array at a particular location. print - print out the array. add - add the elements of one array to another. subtract - subtract the elements of one array from another.
The output of my program is suppose to look like this:
Set q1: 2, 3, 4 Print q1: 2, 3, 4
Set q2: 1, 4, -2 Print q2: 1, 4, -2
Add q2 to q1
Print q1: 3, 7, 2 Get q1 at 1: 7
Here is the code I have so far.
*main.cpp*
#include <iostream> #include "SafeArray.h" using namespace std; int main() {
I have a list of integers that i wish to store in some kind of array. However i do not know how many integers are needed to be stored each time i run my program so i therefore cannot define a size for my array.
I'm simply trying to locate possible logic errors because if I could fill this list properly, I can finish my project very easily. This is just a small portion of a very immersive project.
I am trying to create a linked list that holds objects of type Location *. I have Location defined as
I wish to clarify but can not find where to edit the OP. I believe the list is still empty because I attempt to do a simple read through the list by accessing the head and then reassigning the list to the tail of the list. However, the program never enters the while loop
I am creating a to-do list application and to store the tasks on the list, I am trying to create a linked list. the code for it so far is as follows:
public class Node //Class for nodes which make up a linked list { //Declaring the data to be stored in each node and next variable to point to the next node public string title; public string description; public string priority; public string finish; public string complete;
[Code] ....
The problem with this arises when I try to create a new node from another class like so:
createForm create = new createForm(); //Creates an object reference to createForm create.ShowDialog(); //Shows the createTask form for creating a new task //Declares variables and stores the return value of methods in createForm string _title = create.getTitle;
[Code] ....
The variables _title etc.. all store values from text boxes as string. However, the code creating the object says the the variables cannot be implicitly converted from type 'string' to 'int'. Why this error is happening??
I just started learning about pointer and reference. * and &
The assignment is " Write a program that stores the following numbers in the array named miles:15,22,16,18,27,23, and 20. Have your program copy the data stored in miles to another array named dist, and then display the values in the dist array. YOur program should use pointer notation when copying and displaying array elements.
And this is what i have so far. But there is an error. I highlighted it with red. It says it's incompatible...
#include <iostream> using namespace std; const int arraynumb = 7; // declaration of keys: number of characters of keys void copyfunc(int *[], int); // function initialized int main() { int miles[arraynumb] = {15, 22, 16, 18, 27, 23, 20};
I want to store a very small number - too small for even a long double. However, I don't need the number to be stored very precisely - in fact, all I really need is the order of magnitude of the number. For example, the number 5.205849034425 X 10^-381 can just be stored as an integer of -381 for my purposes. I don't really care about the precision of the 5.205849034425 part.
The reason I get this very small number, is because I am multiplying together thousands of numbers, all of which are around 0.0001 in value. So, one way to do this would be to store all these individual values as simply their order of magnitude (e.g. -4) and then instead of multiplying the numbers, I would just add up their orders of magnitude. However, I am wondering whether there is a way in C++ to do this without me having to change the way I store my data - I still would like to keep the original values if possible.
i'm having difficulty with a problem, i need to add two big numbers suchas 54646774456776 and another one 445556777554 and it would print the result. how can i approach this problem without the use of arrays?
I'm supposed to write a code that takes an integer and splits it into individual numbers e.g. 234 becomes 2 3 4 .the individual numbers are then passed on to a function that accepts only one number at a time
All i could think of was this,but its a very bad method coz i dont know how long a number would be inputed into "Angle_in_degree"
Alexandra has some distinct integer numbers a1,a2...an.
Count number of pairs (i,j) such that: 1≤ i ≤ n 1≤ j ≤ n ai < aj
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer n denoting the number of numbers Alexandra has. The second line contains n space-separated distinct integers a1, a2, ..., an denoting these numbers.
Output
For each test case, output a single line containing number of pairs for corresponding test case.
Constraints
1 ≤ T ≤ 4 1 ≤ n ≤ 100000 0 ≤ ai ≤ 109 All the ai are distinct
Example
2 2 2 1 3 3 1 2
Output: 1 3
Explanation
Case 1: Only one such pair: (2,1) Case 2: 3 possible pairs: (2,1), (2,3), (3,1)
as I understand the problem is just counting how many Ai's are 1 <= Ai <= N and then apply ((R*(R-1))/2), R is the count of valid Ai's
#include <iostream> #include<fstream> int decryption(int); int multiply(int,int[][2]); using namespace std; main(){ int n; ifstream inFile; inFile.open ("out.txt");
[Code] .....
I was trying to store numbers read from a text file into 2D array but I am getting the error above.here is where the error occurs:
Write a C program that sorts an unsorted array of 5 integer numbers in ascending order by swapping numbers repeatedly. Specifically, first prompt the user to input 5 numbers and store the numbers in an array. Then, if the numbers in the array are not in ascending order, ask the user to provide the indices of two numbers in the array that the user wants to swap. If the user does not enter valid indices (i.e., outside 0 to4), then re-prompt the user to enter new indices. Continue prompting the user to provide indices of numbers to swap until the array becomes sorted in ascending order. Finally, when the array becomes sorted, the program should print "The array is now sorted in ascending order".
Implementation Requirements
Use the #define directive to define the size of the array.
Implement a function called "checkArrayOrder" to check whether an array is in ascending order or not. The prototype of the function is
"intcheckArrayOrder(int arr[], int size);". The function should return
1 if the array passed to the function is in ascending order0 if the array passed to the function is not in ascending order
Define the function prototype in your program.
Implement a function called "swap", whose prototype is "int swap(int arr[], int size, int i, int j);" which swaps the numbers in positions "i" and "j" of the array passed to the function and returns
1 if the indices"i" and "j" are within bounds (i.e., between 0 and 4) and the swap operation is performed correctly. 0 if the indices"i" and "j" are outside bounds so that the swap operation cannot be performed.
Define the function prototype in your program.
Use the function "checkArrayOrder" whenever your program needs to check whether an array is in ascending order or not; and the function "swap" to swap the numbers the user specifies (Note that, you should check whether the user provided indices are valid inside the function "swap" and not inside "main").
here is my code so far
Code: #define ARRAY_SIZE 5 void main() { int i, array[ARRAY_SIZE];
I'm trying to write a function called 'set' that sets the value of the i'th cell to val on my linkedList, and then returns the previous contents. I am stuck on it due to compiling errors:
template <typename T> T set(Node<T> *head, int i, const T &val) { for(int n = 0; n < i; n++) if(head == val) { val = i; } return val; } #endif
When I try to call it in the main() I get these errors:
node_utils.h: In function ‘T set(Node<T>*, int, const T&) [with T = int]’: node_demo.cpp:26:38: instantiated from here node_utils.h:161:2: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] node_utils.h:162:3: error: assignment of read-only reference ‘val’
So, I understand that I can't compare head & val on my if-statement -- But what do I do?
Write a program asks the user for a positive integer value and then prints out all perfect numbers from 1 to that positive integer. I have been trying for some time, i found a way to check if its a perfect number or not but could not find a way to prints out all perfect numbers from 1 to that positive integer. I am here so far.
#include<iostream> #include<iomanip> using namespace std; int main(){ int n,i=1,sum=0; cout<<"Enter a number: ";
Why this class doesn't work for Subtraction, Division and Square Root. When I try to get results for Subtraction, it output right answer, but with any trash. And When I try to get answer for Division and Square Root, it just brakes and don't output anything. For Addition and Multiplication class work correctly.
I have to write a program where the user will input integer numbers. How many numbers they enter is unknown, therefor you should use a repetition structure for the input. When the user is done, they will enter -1 to exit.
Create a dynamic array if the size=2( the initial size must be 2) Repeat until user enters -1.
I have to do this without using vectors.
This is what i have, I cannot figure out what to put in main. I was thinking of a do-while?
Code: #include <iostream> using namespace std; void resize(int *[], int); int main() { int *listDyn; int size=2;
I want to count all the numbers in my text file (read.txt). Read text file consist of floating and integer number. Answer for the above file would be integer=2 and float =10.
My program is almost done all that is left is entering big numbers, the program can add and subtract small numbers but not big numbers because it puts them all in one node, I need the program to store each number in a node.
#include<iostream> #include<string> using namespace std; class Node { public: int value; Node * next;
This is one part of my program, I need a loop that checks through the input(specifically the agent numbers) and then outputs the agent numbers that aren't in the input, from 1 to 20(because there should only be 20 agent).
the first numbers are the agent numbers so 1 , 2 ,15 are agent numbers and out output for agents who didnt participate are : 2 , 5 , 6 , 7, 8, 9, 10 , 11 , 14 , 16 , 17 ,19 20
this is the code ive wrote but its not working.
void not_part() { ins.open(in_file); int i=0; int sum=0; cout<<"AGENTS WHO DID NOT PARTICIPATE IN THE CAMPAIGN"<<endl; cout<<fixed<<showpoint;